Home > Java > javaTutorial > body text

What are the methods of declarative transactions in java

PHPz
Release: 2023-05-16 19:10:59
forward
1589 people have browsed it

1. Declarative transactions

Use AOP (aspect-oriented) method to open the transaction using the programmatic transaction method before the method, and submit or submit after the method rollback. Use configuration file methods or annotation methods (such as @Transactional) to control transactions.

The annotation on the method is that the method automatically starts the transaction, and on the class it is that all methods in the entire class use transactions

2. Method

1. Declarative transaction management based on TransactionProxyFactoryBean

Configure in applicationContext.xml

What are the methods of declarative transactions in java

Then when needed The service layer for transaction management injects the proxy class accountrviceProxy

@Resource(name="accountrviceProxy")
Copy after login

This method has a disadvantage, that is, we need to match each service class that needs transaction management with its proxy class, which is relatively easy to configure. Cumbersome.

2. Declarative transaction management based on AspectJ XML

There is an expression when configuring the entry point:

expression="execution(* com.cn.study.spring.service.IAccountService+.*(..))"
Copy after login

execution in brackets The parameters in turn represent the method return type, package name, class name, method name and method parameters

where * represents any

IAccountService represents the methods of all implementation classes of the IAccountService interface

This method is one of the more commonly used.

3. Declarative transaction management based on annotations

The third way is the simplest. We only need to configure the driver that enables annotation transactions in applicationContext.xml, and then Add annotations before the classes that require transaction management:

@Transactional(propagation=Propagation.REQUIRED)
Copy after login

The above is the detailed content of What are the methods of declarative transactions in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!