applicationContext.xml 8.5 KB
Newer Older
afe's avatar
afe committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc"  
	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:cache="http://www.springframework.org/schema/cache"  
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
		http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.2.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
		http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd  
		http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.2.xsd  
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
		http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd"
	default-lazy-init="true">

	<description>Spring公共配置 </description>

	<!-- 使用annotation 自动注册bean, 并保证@Required、@Autowired的属性被注入 -->
	<context:component-scan base-package="com.hp.cmsz">
		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
		<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
	</context:component-scan>

    <!--  -->
   <!--  <bean id="tagCacheManager" class="">
		<property name="cacheManagerConfigFile" value=""/>
	</bean> -->

    <!-- 缓存配置 -->  
    <!-- 启用缓存注解功能(请将其配置在Spring主配置文件中) -->  
 <!--   <cache:annotation-driven cache-manager="cacheManager"/>   --> 
    <!-- Spring自己的基于java.util.concurrent.ConcurrentHashMap实现的缓存管理器(该功能是从Spring3.1开始提供的) -->  
    <!--   
    <bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">  
        <property name="caches">  
            <set>  
                <bean name="myCache" class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"/>  
            </set>  
        </property>  
    </bean>  
     -->  
    <!-- 若只想使用Spring自身提供的缓存器,则注释掉下面的两个关于Ehcache配置的bean,并启用上面的SimpleCacheManager即可 -->  
    <!-- Spring提供的基于的Ehcache实现的缓存管理器 -->  
<!--  <bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">  
        <property name="configLocation" value="classpath:ehcache/ehcache.xml"/>  
    </bean>  
    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">  
        <property name="cacheManager" ref="cacheManagerFactory"/>  
    </bean>  
  -->  
	
	
  <!-- 监视和优化sql -->
  <bean id="dataSource" class="com.p6spy.engine.spy.P6DataSource" >    
       <constructor-arg>    
           <ref local="dataSourceTarget"/>    
       </constructor-arg>    
  </bean>    
  
  <!-- 4A相关的WebService-->
<!-- Amend by huach for webservice on 20140725 begin  
   <import resource="classpath:org/codehaus/xfire/spring/xfire.xml" />
    <bean id="addressingHandler" class="org.codehaus.xfire.addressing.AddressingInHandler" />-->
  <!-- <bean id="LoginSwitchBean" class="com.cmsz.ws.impl.LoginSwitchServiceImpl"/>
  
 
  
  <bean id="GroupBean" class="com.cmsz.ws.impl.GroupServiceImpl"/>
  
  <bean id="LogoutBean" class="com.cmsz.ws.impl.LogoutServiceImpl"/> -->
  
  <!-- <bean id="userService" class="com.cmsz.ws.impl.UserServiceImpl"/> 
  
		<bean name="UserService" class="org.codehaus.xfire.spring.ServiceBean">

			<property name="serviceBean" ref="userServiceBean" />

			<property name="serviceClass" value="com.cmsz.ws.UserService" />

			<property name="inHandlers">

				<list>

					<ref bean="addressingHandler" />

				</list>

			</property>

		</bean>
		<bean id="userServiceBean" class="com.cmsz.ws.impl.UserServiceImpl" /> 
-->		
		<!--  <bean id="DepartmentBean" class="com.cmsz.ws.impl.DepartmentServiceImpl"/> 
		 	<bean name="DepartmentService" class="org.codehaus.xfire.spring.ServiceBean">
			<property name="serviceBean" ref="departmentServiceBean" />
			<property name="serviceClass"
				value="com.cmsz.ws.DepartmentService" />
			<property name="inHandlers">
				<list>
					<ref bean="addressingHandler" />
				</list>
			</property>
		</bean>
		<bean id="departmentServiceBean" class="com.cmsz.ws.impl.DepartmentServiceImpl" />
		-->
  <!-- Amend by huach for webservice on 20140725 end -->
  
  	<!-- 让springmvc支持文件上传 -->
	<!-- <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    	<property name="maxInMemorySize" value="2048"></property>
    	<property name="maxUploadSize" value="1000000000"/>
    </bean> -->
  
	<!-- Jpa Entity Manager 配置 -->
	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
		<property name="dataSource" ref="dataSource"/>
		<property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
		<property name="packagesToScan" value="com.hp.cmsz"/>
		<property name="jpaProperties">
			<props>
				<!-- 命名规则 My_NAME->MyName -->
				<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
			</props>
		</property>
	</bean>
	
	<bean id="hibernateJpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
		<property name="databasePlatform">
			<bean factory-method="getDialect" class="org.springside.modules.persistence.Hibernates">
				<constructor-arg ref="dataSource"/>
			</bean>
		</property>
	</bean>

	<!-- Spring Data Jpa配置 -->
 	<jpa:repositories base-package="com.hp.cmsz"  transaction-manager-ref="transactionManager" entity-manager-factory-ref="entityManagerFactory"/>
   
	<!-- Jpa 事务配置 -->
	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactory"/>
	</bean>

	<!-- 使用annotation定义事务 -->
	<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />

	<!-- JSR303 Validator定义 -->
 	<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" />
	
	
	
  	
  	
	<!-- production环境 -->
 	<beans profile="production">
 		<context:property-placeholder ignore-unresolvable="true"
			location="classpath*:/application.properties" />	
			
		<!-- 数据源配置, 使用Tomcat JDBC连接池 -->
		<bean id="dataSourceTarget" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
			<!-- Connection Info -->
			<property name="driverClassName" value="${jdbc.driver}" />
			<property name="url" value="${jdbc.url}" />
			<property name="username" value="${jdbc.username}" />
			<property name="password" value="${jdbc.password}" />
		
			<!-- Connection Pooling Info -->
			<property name="maxActive" value="${jdbc.pool.maxActive}" />
			<property name="maxIdle" value="${jdbc.pool.maxIdle}" />
			<property name="defaultAutoCommit" value="false" />
			<!-- 连接Idle一个小时后超时 -->
			<property name="timeBetweenEvictionRunsMillis" value="3600000" />
			<property name="minEvictableIdleTimeMillis" value="3600000" />
		</bean>
		
		<!-- 数据源配置,使用应用服务器的数据库连接池 -->
		<!--<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/ExampleDB" />-->
	</beans>
	
	<!-- local development环境 -->
	<beans profile="development">
		<context:property-placeholder ignore-resource-not-found="true"
			location="classpath*:/application.properties" />	

		<!-- Tomcat JDBC连接池 -->
		<bean id="dataSourceTarget" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
			<property name="driverClassName" value="${jdbc.driver}" />
			<property name="url" value="${jdbc.url}" />
			<property name="username" value="${jdbc.username}" />
			<property name="password" value="${jdbc.password}" />
			<property name="defaultAutoCommit" value="false" />
		</bean>

	</beans>
	
</beans>