<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:cache="http://www.springframework.org/schema/cache"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd   
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
	http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd">

	<context:property-placeholder location="classpath*:*.properties" />

	<bean class="com.uas.platform.b2b.core.support.ApplicationContextRegister" />

	<context:component-scan base-package="com.uas.platform" />
	<context:annotation-config />

	<!-- 国际化的消息资源文件（本系统中主要用于显示/错误消息定制） -->
	<bean id="messageSource"
		class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
		<property name="basenames">
			<list>
				<value>classpath:spring/messages</value>
			</list>
		</property>
		<property name="useCodeAsDefaultMessage" value="false" />
		<property name="defaultEncoding" value="UTF-8" />
		<property name="cacheSeconds" value="60" />
	</bean>

	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
		destroy-method="close">
		<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="initialSize" value="${jdbc.initialSize}" />
		<!-- 连接池的最大值，同一时间可以从池分配的最多连接数量，0时无限制 -->
		<property name="maxActive" value="${jdbc.maxActive}" />
		<!-- 最大空闲值.当经过一个高峰时间后，连接池可以慢慢将已经用不到的连接慢慢释放一部分，一直减少到maxIdle为止 ，0时无限制 -->
		<property name="maxIdle" value="${jdbc.maxIdle}" />
		<!-- 最小空闲值.当空闲的连接数少于阀值时，连接池就会预申请去一些连接，以免洪峰来时来不及申请 -->
		<property name="minIdle" value="${jdbc.minIdle}" />
		<!-- 是否对已备语句进行池管理（布尔值），是否对PreparedStatement进行缓存 -->
		<property name="poolPreparedStatements" value="true" />
		<!-- 是否对sql进行自动提交 -->
		<property name="defaultAutoCommit" value="true" />
		<!-- 回收超时连接 -->
		<property name="removeAbandoned" value="true" />
		<!-- 连接空闲时校验连接有效性 -->
		<property name="testWhileIdle" value="true" />
		<!-- 校验连接有效性的sql -->
		<property name="validationQuery" value="select 1 from dual" />
		<!-- 每过timeBetweenEvictionRunsMillis 时间，就会启动一个线程，校验连接池中闲置时间超过minEvictableIdleTimeMillis的连接对象 -->
		<property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" />
		<property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}" />
	</bean>
	<!-- hibernate jpa -->
	<bean class="org.springframework.orm.jpa.JpaTransactionManager"
		id="transactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactory" />
	</bean>
	<tx:annotation-driven mode="aspectj"
		transaction-manager="transactionManager" />

	<bean id="transactionInterceptor"
		class="org.springframework.transaction.interceptor.TransactionInterceptor">
		<property name="transactionManager" ref="transactionManager" />
		<property name="transactionAttributeSource">
			<bean
				class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"></bean>
		</property>
	</bean>

	<bean id="transactionAttributeSourceAdvisor"
		class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
		<property name="transactionInterceptor" ref="transactionInterceptor" />
	</bean>

	<bean id="entityManagerFactory"
		class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
		<property name="persistenceUnitName" value="persistenceUnit" />
		<property name="packagesToScan" value="com.uas.platform" />
		<property name="dataSource" ref="dataSource" />
		<property name="jpaVendorAdapter">
			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
				<property name="generateDdl" value="false" />
				<property name="databasePlatform" value="org.hibernate.dialect.Oracle10gDialect" />
				<property name="showSql" value="false" />
			</bean>
		</property>
		<property name="jpaDialect">
			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
		</property>
		<property name="jpaProperties">
			<props>
				<prop key="hibernate.cache.provider_configuration_file_resource_path">classpath:spring/ehcache.xml</prop>
				<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
				</prop>
				<prop key="hibernate.cache.use_query_cache">true</prop>
				<prop key="hibernate.cache.use_second_level_cache">true</prop>
				<prop key="hibernate.generate_statistics">true</prop>
				<prop key="hibernate.use_sql_comments">true</prop>
				<prop key="hibernate.format_sql">true</prop>
				<prop key="hibernate.generate_statistics">true</prop>
			</props>
		</property>
	</bean>
	<!-- jdbctemplate -->
	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource" ref="dataSource" />
	</bean>
	<!-- 使用ehcache对象缓存 -->
	<cache:annotation-driven />
	<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
		<property name="cacheManager" ref="ehcache"></property>
	</bean>
	<bean id="ehcache"
		class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
		<property name="configLocation" value="classpath:spring/ehcache.xml"></property>
		<property name="shared" value="true"></property>
	</bean>
	<!-- mail sender -->
	<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
		<property name="host" value="${email.host}" />
		<property name="port" value="${email.port}" />
		<property name="javaMailProperties">
			<props>
				<prop key="mail.smtp.auth">true</prop>
				<prop key="mail.smtp.timeout">25000</prop>
				<prop key="mail.smtp.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
				<prop key="mail.smtp.port">465</prop>
				<prop key="mail.smtp.socketFactory.port">465</prop>
			</props>
		</property>
		<property name="username" value="${email.username}" />
		<property name="password" value="${email.password}" />
	</bean>
	<bean id="simpleMailMessage" class="org.springframework.mail.SimpleMailMessage">
		<property name="from" value="${email.from}" />
	</bean>
	<bean id="velocityEngine"
		class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
		<property name="velocityProperties">
			<props>
				<prop key="resource.loader">class</prop>
				<prop key="class.resource.loader.class">
					org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
				</prop>
				<prop key="velocimacro.library"></prop>
			</props>
		</property>
	</bean>
	<!-- 文件上传 -->
	<bean id="multipartResolver"
		class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
		<property name="defaultEncoding" value="utf-8"></property>
	</bean>
</beans>