sping的事务管理

    技术2022-05-13  21

    <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!-- 建立数据源bean --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>com.mysql.jdbc.Driver</value> </property> <property name="url"> <value>jdbc:mysql://localhost:3306/ssh?useUnicode=true&characterEncoding=UTF-8</value> </property> <property name="username"> <value>root</value> </property> <property name="password"> <value>root</value> </property> </bean> <!-- 定义目标对象 --> <bean id="customerManagerTarget" class="com.spring.CustomerManagerTarget"> ...... </bean> <!-- 定义事务管理器 --> <bean id="transactionManger" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource"> <ref bean="dataSource""/> </property> </bean> <!-- 定义事务策略 --> <bean id="transactionAttributeSource"> <property name="properties"> <props> <prop key="add"> PROPAGATION_REQUIRES_NEW </prop> </props> </property> </bean> <!-- 定义事物代理,声明式的事务管理 --> <bean id="CustomerManager" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <!-- 注入代理实现的接口,可以使接口列表 --> <property name="proxyInterfaces"> <value>com.spring.CustomerManager</value> </property> <!-- 注入事务管理的目标对象 --> <property name="target"> <ref bean="customerManagerTarget"/> </property> <!-- 注入事物管理器 --> <property name="transactionManager"> <ref bean="transacionManager"/> </property> <!-- 注入事务管理策略 --> <property name="transactionAttributeSource"> <ref bean="transactionAttributeSource"/> </property> </bean> </beans>


    最新回复(0)