spring-config.xml
<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:property-placeholder location="classpath:jdbc.properties" ignore-unresolvable="true" />
<!-- 扫描注解Bean -->
<context:component-scan base-package="cn.yihai">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<aop:aspectj-autoproxy expose-proxy="true" />
<bean class="cn.yihai.basic.utils.SpringUtils" />
<import resource="classpath:spring/datasource/main.xml" />
<import resource="classpath:spring/spring-quartz.xml" />
</beans>
main.xml
<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
<bean id="mainDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.main.driver}" />
<property name="url" value="${jdbc.main.url}" />
<property name="username" value="${jdbc.main.username}" />
<property name="password" value="${jdbc.main.password}" />
<property name="initialSize" value="${jdbc.initialSize}" />
<property name="minIdle" value="${jdbc.minIdle}" />
<property name="maxIdle" value="${jdbc.maxIdle}" />
<property name="maxActive" value="${jdbc.maxActive}" />
<property name="maxWait" value="${jdbc.maxWait}" />
<property name="defaultAutoCommit" value="${jdbc.defaultAutoCommit}" />
<property name="removeAbandoned" value="${jdbc.removeAbandoned}" />
<property name="removeAbandonedTimeout" value="${jdbc.removeAbandonedTimeout}" />
<property name="testWhileIdle" value="${jdbc.testWhileIdle}" />
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.timeBetweenEvictionRunsMillis}" />
<property name="numTestsPerEvictionRun" value="${jdbc.numTestsPerEvictionRun}" />
<property name="minEvictableIdleTimeMillis" value="${jdbc.minEvictableIdleTimeMillis}" />
<property name="logAbandoned" value="${jdbc.logAbandoned}" />
<property name="connectionInitSqls" value="set names utf8mb4;" />
</bean>
<bean id="jdbcTemplateMain" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="mainDataSource" />
</bean>
<!-- 事务管理器配置 -->
<bean id="main" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="mainDataSource" />
</bean>
<!-- 使用annotation定义事务 -->
<tx:annotation-driven transaction-manager="main" proxy-target-class="true" />
</beans>
jdbc.properties
jdbc.main.driver=
jdbc.main.url=
jdbc.main.username=
jdbc.main.password=
jdbc.initialSize=2
jdbc.minIdle=0
jdbc.maxIdle=5
jdbc.maxActive=10
jdbc.maxWait=30000
jdbc.defaultAutoCommit=false
jdbc.removeAbandoned=true
jdbc.removeAbandonedTimeout=60
jdbc.testWhileIdle=true
jdbc.timeBetweenEvictionRunsMillis=10000
jdbc.numTestsPerEvictionRun=20
jdbc.minEvictableIdleTimeMillis=10000
jdbc.logAbandoned=true