applicationContext.xml 6.1 KB
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:jpa="http://www.springframework.org/schema/data/jpa"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop.xsd
       http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/tx/spring-tx.xsd
       http://www.springframework.org/schema/data/jpa 
       http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">

	<!-- 配置此项可以使用Annotation -->
	<context:annotation-config />
	<!-- 扫描包 -->
	<context:component-scan
		base-package="com.framework.mail,com.agent.service,com.agent.repository" />
	<!-- 使用Aop -->
	<aop:aspectj-autoproxy />

	<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<property name="locations">
			<list>
				<value>classpath:datasource.properties</value>
				<value>classpath:application.properties</value>
			</list>
		</property>
	</bean>

	<!-- 配置DataSource 使用Druid连接池 -->
	<bean id="dataSource" init-method="init" destroy-method="close"
		class="com.alibaba.druid.pool.DruidDataSource">
		<property name="DriverClassName" value="${jdbc.driverClassName}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		<!-- 连接池最大使用连接数量 -->
		<property name="maxActive" value="${maxActive}" />
		<!-- 初始化大小 -->
		<property name="initialSize" value="${initialSize}" />
		<!-- 获取连接最大等待时间 -->
		<property name="maxWait" value="${maxWait}" />
		<!-- 连接池最小空闲 -->
		<property name="minIdle" value="${minIdle}" />
		<!-- 逐出连接的检测时间间隔 -->
		<property name="timeBetweenEvictionRunsMillis" value="${timeBetweenEvictionRunsMillis}" />
		<!-- 最小逐出时间 -->
		<property name="minEvictableIdleTimeMillis" value="${minEvictableIdleTimeMillis}" />
		<!-- 测试有效用的SQL Query <property name="validationQuery" value="SELECT 1" 
			/> -->
		<!-- 连接空闲时测试是否有效 -->
		<property name="testWhileIdle" value="true" />
		<!-- 获取连接时测试是否有效 -->
		<property name="testOnBorrow" value="false" />
		<!-- 归还连接时是否测试有效 -->
		<property name="testOnReturn" value="false" />
	</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.agent.entity" />
		<property name="jpaProperties">
			<props>
				<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
				<prop key="net.sf.ehcache.configurationResourceName">cache/ehcache-hibernate-local.xml</prop>
				<prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
				<prop key="hibernate.show_sql">${showSql}</prop>
				<prop key="hibernate.format_sql">${formatSql}</prop>
				<prop key="hibernate.hbm2ddl.auto">${generateDdl}</prop>
			</props>
		</property>
	</bean>

	<bean id="hibernateJpaVendorAdapter"
		class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
		<property name="databasePlatform">
			<bean factory-method="getDialect" class="com.framework.core.Hibernates">
				<constructor-arg ref="dataSource" />
			</bean>
		</property>
	</bean>

	<!-- 事务配置 Start -->
	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactory" />
	</bean>
	<tx:annotation-driven transaction-manager="transactionManager"
		proxy-target-class="true" />
	<!-- 事务配置End -->

	<!-- spring data jpa -->
	<jpa:repositories base-package="com.agent.repository"
		entity-manager-factory-ref="entityManagerFactory"
		transaction-manager-ref="transactionManager">
	</jpa:repositories>

	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<!-- velocity 模板引擎 -->
	<bean id="velocityEngine"
		class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
		<property name="velocityProperties">
			<props>
				<prop key="resource.loader">file</prop>
				<prop key="file.resource.loader.class">org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader</prop>
				<prop key="file.resource.loader.cache">false</prop>
				<prop key="file.resource.loader.modificationCheckInterval">3</prop>
				<prop key="input.encoding">UTF-8</prop>
				<prop key="output.encoding">UTF-8</prop>
			</props>
		</property>
	</bean>

	<!-- 配置邮件 senderbean -->
	<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
		<property name="host" value="${mail.smtp.host}"></property>
		<property name="javaMailProperties">
			<props>
				<prop key="mail.smtp.auth">${mail.smtp.auth}</prop>
				<prop key="mail.smtp.timeout">${mail.smtp.timeout}</prop>
			</props>
		</property>
		<property name="username" value="${mail.smtp.username}"></property>
		<property name="password" value="${mail.smtp.password}"></property>
	</bean>

	<bean id="org.apache.cxf.wstx_msv_validation.WoodstoxValidationImpl"
		class="org.apache.cxf.wstx_msv_validation.WoodstoxValidationImpl"
		lazy-init="true">
		<constructor-arg ref="cxf" />
	</bean>
	
	<bean id="startupListener" class="com.agent.listener.StartupListener"/>
	
	<bean id="SpringContextKit" class="com.agent.billcheck.SpringContextKit" scope="singleton"></bean>

</beans>