<aop:aspectj-autoproxy></aop:aspectj-autoproxy>
定义数据源连接:
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/usercenter?characterEncoding=utf-8&autoReconnect=true">
</property>
<property name="username" value="1111"></property>
<property name="password" value="1111"></property>
<property name="testWhileIdle" value="true"></property>
<property name="validationQuery" value="select 1"></property>
</bean>
编程式事务管理
<bean id ="txManager" class = "org.springframework.jbbc.datasource.DateSourceTransactionManager">
<property name = "dataSource" ref = "dataSource"/></bean>
需要注入的代码
<tx:advice id="userTxAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" />
</tx:attributes>
</tx:advice>
动态代理配制
<aop:config>
<aop:pointcut expression="execution(* com.jzxk.usercenter.dao.*.*(..))" id="userOperation"/>
组合使用:
<aop:advisor advice-ref="userTxAdvice" pointcut-ref="userOperation"/>
</aop:config>
transactionManager定义
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref bean="dataSource"/>
对数据库连接池的操作进行事务控制,正确时提交,错误时回滚,保持数据正确。
定义数据源连接:
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/usercenter?characterEncoding=utf-8&autoReconnect=true">
</property>
<property name="username" value="1111"></property>
<property name="password" value="1111"></property>
<property name="testWhileIdle" value="true"></property>
<property name="validationQuery" value="select 1"></property>
</bean>
编程式事务管理
<bean id ="txManager" class = "org.springframework.jbbc.datasource.DateSourceTransactionManager">
<property name = "dataSource" ref = "dataSource"/></bean>
需要注入的代码
<tx:advice id="userTxAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" />
</tx:attributes>
</tx:advice>
动态代理配制
<aop:config>
<aop:pointcut expression="execution(* com.jzxk.usercenter.dao.*.*(..))" id="userOperation"/>
组合使用:
<aop:advisor advice-ref="userTxAdvice" pointcut-ref="userOperation"/>
</aop:config>
transactionManager定义
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource">
<ref bean="dataSource"/>
对数据库连接池的操作进行事务控制,正确时提交,错误时回滚,保持数据正确。