<?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:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:task="http://www.springframework.org/schema/task"
       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/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/data/jpa 
http://www.springframework.org/schema/data/jpa/spring-jpa-1.2.xsd 
http://www.springframework.org/schema/task 
http://www.springframework.org/schema/task/spring-task.xsd
">
    <!-- 引入属性文件 <context:property-placeholder location="classpath:jdbc.properties"
        /> -->

    <!-- 自动扫描dao和service包(自动注入) -->
    <context:component-scan base-package="cn.com.qmth.stmms.biz"/>
    <context:component-scan base-package="cn.com.qmth.stmms.admin.thread"/>

    <import resource="spring-jpa.xml"/>

    <!-- dbcp数据源 -->
    <bean name="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
          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="maxActive" value="${jdbc.maxActive}"/>
        <property name="initialSize" value="${jdbc.initSize}"/>
        <property name="maxWait" value="60000"/>
        <property name="maxIdle" value="5"/>
        <property name="minIdle" value="5"/>
        <property name="minEvictableIdleTimeMillis" value="1800000"/>
        <property name="timeBetweenEvictionRunsMillis" value="60000"/>
        <property name="testWhileIdle" value="true"/>
        <property name="testOnBorrow" value="false"/>
        <property name="validationQuery" value="SELECT 1 FROM DUAL"/>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
    </bean>

    <!-- 指定事务声明的配置方式：使用注解的方式 -->
    <tx:annotation-driven transaction-manager="transactionManager"/>

    <bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="database" value="MYSQL"/>
                <property name="showSql" value="false"/>
                <property name="generateDdl" value="true"/>
            </bean>
        </property>
    </bean>

    <task:executor id="task-executor" pool-size="5"/>
    <task:executor id="cron-executor" pool-size="5"/>
    <task:scheduler id="cron-scheduler" pool-size="5"/>
    <task:annotation-driven executor="cron-executor" scheduler="cron-scheduler"/>
</beans>
