1. Programming Transactions
Concept: Transaction control code is programmed by programmers
Example: OpenSession InView
2. Declarative transactions
- Concept:
Transaction control code has been written by spring. Programmers only need to state which methods need transaction control and how to control transactions. - Declarative transactions are for methods under the ServiceImpl class
- Transaction manager based on advice
- Configuring declarative transactions in spring configuration files
Transaction Manager
Declare which methods require transaction management
Need Cut Point Configuration Based on Notification Writing
<!-- Attribute file-based configuration needs to add this sentence --> <context:property-placeholder location="classpath:db.properties,classpath:second.pr operties"/> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverMa nagerDataSource"> <property name="driverClassName" value="${jdbc.driver}"></property> <property name="url" value="${jdbc.url}"></property> <property name="username" value="${jdbc.username}"></property> <property name="password" value="${jdbc.password}"></property> </bean> <!-- spring-jdbc.jar in --> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSour ceTransactionManager"> <!-- The transaction manager needs to connect to the data source before it can take effect --> <property name="dataSource" ref="dataSource"></property> </bean> <!-- Configuring declarative transactions --> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <!-- Which methods need transaction control --> <!-- Method to ins Beginning transaction management --> <tx:method name="ins*" /> <tx:method name="del*" /> <tx:method name="upd*" /> <tx:method name="*" /> </tx:attributes> </tx:advice> <!--Collocation points--> <aop:config> <!-- Setting up a wider range of tangent points --> <aop:pointcut expression="execution(* com.youdian.service.impl.*.*(..))" id="mypoint" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="mypoint" /> </aop:config>