<?xml version="1.0" encoding="UTF-8"?>
<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:jpa="http://www.springframework.org/schema/data/jpa"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
	   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">

	<!-- 注册spring上下文对象 -->
	<bean class="com.uas.platform.b2b.manage.core.support.ApplicationContextRegister" />

	<!-- 扫描注解 -->
	<context:annotation-config />
	<!-- 扫描的包 -->
	<context:component-scan base-package="com.uas.platform.b2b.manage" />

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

    <jpa:repositories base-package="com.uas.platform.b2b.manage.dao"/>

    <bean id="dataSource" class="com.uas.platform.b2b.manage.support.MultiDataSource">
		<property name="dataSource">
			<ref bean="defaultDataSource" />
		</property>
		<property name="connectionProperties" >
			<props>
				<prop key="oracle.net.CONNECT_TIMEOUT">6000</prop>
				<prop key="oracle.jdbc.ReadTimeout">6000</prop>
				<prop key="oracle.net.READ_TIMEOUT">6000</prop>
			</props>
		</property>
	</bean>
	<bean id="defaultDataSource" class="com.alibaba.druid.pool.DruidDataSource"
		  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}" />
		<!-- 最小空闲值.当空闲的连接数少于阀值时，连接池就会预申请去一些连接，以免洪峰来时来不及申请 -->
		<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="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}" />
		<!-- 连接空闲时校验连接有效性 -->
		<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>

	<bean class="org.springframework.orm.jpa.JpaTransactionManager"
		  id="transactionManager">
		<property name="entityManagerFactory" ref="entityManagerFactory" />
	</bean>
    <bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <!--<property name="persistenceUnitName" value="persistenceUnit" />-->
        <property name="persistenceXmlLocation" value="classpath*:META-INF/persistence.xml" />
        <property name="packagesToScan" value="com.uas.platform.b2b.manage" />
        <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.MySQL5Dialect" />
                <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>
</beans>