Home> Java> javaTutorial> body text

Detailed explanation of five injection methods of Spring transaction Transaction configuration

Y2J
Release: 2017-05-02 11:37:32
Original
1823 people have browsed it

This article mainly introduces the five injection methods of Spring transaction configuration in detail. It has certain reference value. Interested friends can refer to it.

I did some in-depth research on spring's transaction configuration some time ago. Although I have also configured Spring's transaction configuration during this period, I have never had a clear understanding of it. Through this study, I found that Spring's transaction configuration is relatively easy to master as long as the ideas are clarified.

The summary is as follows:

The transaction configuration in the Spring configuration file always consists of three components, namely DataSource, TransactionManager and proxy mechanism. No matter where A configuration method, generally only the proxy mechanism changes.

DataSource and TransactionManager will only change according to the data access method. For example, when using hibernate for data access, the DataSource is actually SessionFactory, and the implementation of TransactionManager is HibernateTransactionManager.

The details are as follows:

#Based on the different proxy mechanisms, five Spring transaction configuration methods are summarized. The configuration files are as follows :

The first way: Each Bean has a proxy


                       PROPAGATION_REQUIRED     
Copy after login

The second way Method: All Beans share a proxy base class

                PROPAGATION_REQUIRED            
Copy after login

Third method: Use interceptor

               PROPAGATION_REQUIRED         *Dao       transactionInterceptor         
Copy after login

Fourth method: Use tx tag configuration Interceptor

                     
Copy after login

The fifth way: full annotation

             
Copy after login

At this time, the @Transactional annotation needs to be added to the DAO, as follows:

package com.bluesky.spring.dao; import java.util.List; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import org.springframework.stereotype.Component; import com.bluesky.spring.domain.User; @Transactional @Component("userDao") public class UserDaoImpl extends HibernateDaoSupport implements UserDao { public List listUsers() { return this.getSession().createQuery("from User").list(); } }
Copy after login

The above is the detailed content of Detailed explanation of five injection methods of Spring transaction Transaction configuration. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
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!