<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.sPRingframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd // 和上面的都是对应存在的 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!-- 配置数据源 -->
<!-- 定义使用C3P0连接池的数据源 -->
<bean id="dbDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"><!-- 指定连接数据库的JDBC驱动 --> <property name="driverClass"> <value>${jdbc.driverClassName}</value> </property><!-- 连接数据库所用的URL --> <property name="jdbcUrl"> <value>${jdbc.db.url}</value> </property><!-- 连接数据库的用户名 --> <property name="user"> <value>${jdbc.db.username}</value> </property><!-- 连接数据库的密码 --> <property name="passWord"> <value>${jdbc.db.password}</value> </property><!-- 设置数据库连接池的最大连接数 --> <property name="maxPoolSize"> <value>${jdbc.maxPoolSize}</value> </property><!-- 设置数据库连接池的最小连接数 --> <property name="minPoolSize"> <value>${jdbc.minPoolSize}</value> </property><!-- 设置数据库连接池的初始化连接数 --> <property name="idleConnectionTestPeriod"> <value>${jdbc.idleConnectionTestPeriod}</value> </property><!-- 设置数据库连接池的连接的最大空闲时间,单位为秒 --> <property name="maxIdleTime"> <value>${jdbc.maxIdleTime}</value> </property> <property name="testConnectionOnCheckout"> <value>${jdbc.testConnectionOnCheckout}</value> </property></bean><!-- 配置一个事务通知 --><tx:advice id="txAdvice" transaction-manager="dbTransactionManager"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="save*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="insert*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="create*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="update*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="delete*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="remove*" propagation="REQUIRED" rollback-for="Exception"/> <tx:method name="*" read-only="true"/> </tx:attributes></tx:advice><!-- 使用XML来使用事务管理--> <aop:config><!-- 配置一个切面,和需要拦截的类和方法 --> <aop:pointcut id="txPointcut" expression="execution(* com..service.*.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/></aop:config></beans>
新闻热点
疑难解答