Spring Several transaction configurations @ and spring required jar packages
Five Ways to configure spring transactions
The previous period of time has done a more in-depth study of the transaction configuration of Spring, in which the transaction configuration of spring has been configured, but there has been no clear understanding. Through this study found that spring's business configuration as long as the idea is clear, or better mastered.
Summarized as follows:
The spring configuration file about transaction configuration is always composed of three components, namely, DataSource, TransactionManager and agent mechanism of the three parts, regardless of which configuration method, the general change is only the agent mechanism this part.
DataSource, TransactionManager These two parts only according to the data access way change, for example uses Hibernate to carry on the data access, DataSource actually is sessionfactory, The implementation of TransactionManager is Hibernatetransactionmanager.
Figure as follows:
According to the different agent mechanism, the configuration of five kinds of spring transactions is summarized, and the configuration file is as follows:
The first way: Each bean has a proxy <? XML version= "1.0" encoding= "UTF-8"?>
< beans xmlns = "Http://www.springframework.org/schema/beans"
Xmlns:xsi = "Http://www.w3.org/2001/XMLSchema-instance"
Xmlns:context = "Http://www.springframework.org/schema/context"
XMLNS:AOP = "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"
Xsi:schemalocation = "Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context-2.5.xsd
HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-2.5.xsd ">
< Bean id = "Sessionfactory"
class = "Org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
< property name = "Configlocation" value = "Classpath:hibernate.cfg.xml"/>
< property name = "ConfigurationClass" value = "Org.hibernate.cfg.AnnotationConfiguration"/>
</Bean >
<!--define the transaction manager (declarative transactions)--
< Bean id = "TransactionManager"
class = "Org.springframework.orm.hibernate3.HibernateTransactionManager" >
< property name = "Sessionfactory" ref = "Sessionfactory"/>
</Bean >
<!--Configuring DAO--
< Bean id = "Userdaotarget" class = "Com.bluesky.spring.dao.UserDaoImpl" >
< property name = "Sessionfactory" ref = "Sessionfactory"/>
</Bean >
< Bean id = "Userdao"
class = "Org.springframework.transaction.interceptor.TransactionProxyFactoryBean" >
<!--configuration Transaction Manager-
< property name = "TransactionManager" ref = "TransactionManager"/>
< property name = "target" ref = "Userdaotarget"/>
< property name = "Proxyinterfaces" value = "Com.bluesky.spring.dao.GeneratorDao"/>
<!--configuring transaction Properties--
< property name = "Transactionattributes" >
< props >
< prop key = "*" > propagation_required </prop >
</Props >
</Property >
</Bean >
</Beans >
The second way: all beans share a proxy base class <? XML version= "1.0" encoding= "UTF-8"?>
< beans xmlns = "Http://www.springframework.org/schema/beans"
Xmlns:xsi = "Http://www.w3.org/2001/XMLSchema-instance"
Xmlns:context = "Http://www.springframework.org/schema/context"
XMLNS:AOP = "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"
Xsi:schemalocation = "Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context-2.5.xsd
HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-2.5.xsd ">
< Bean id = "Sessionfactory"
class = "Org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
< property name = "Configlocation" value = "Classpath:hibernate.cfg.xml"/>
< property name = "ConfigurationClass" value = "Org.hibernate.cfg.AnnotationConfiguration"/>
</Bean >
<!--define the transaction manager (declarative transactions)--
< Bean id = "TransactionManager"
class = "Org.springframework.orm.hibernate3.HibernateTransactionManager" >
< property name = "Sessionfactory" ref = "Sessionfactory"/>
</Bean >
< Bean id = "Transactionbase"
class = "Org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
Lazy-init = "true" abstract = "true" >
<!--configuration Transaction Manager-
< property name = "TransactionManager" ref = "TransactionManager"/>
<!--configuring transaction Properties--
< property name = "Transactionattributes" >
< props >
< prop key = "*" > propagation_required </prop >
</Props >
</Property >
</Bean >
<!--Configuring DAO--
< Bean id = "Userdaotarget" class = "Com.bluesky.spring.dao.UserDaoImpl" >
< property name = "Sessionfactory" ref = "Sessionfactory"/>
</Bean >
< Bean id = "Userdao" parent = "Transactionbase" >
< property name = "target" ref = "Userdaotarget"/>
</Bean >
</Beans >
The third way: the use of interceptors <? XML version= "1.0" encoding= "UTF-8"?>
< beans xmlns = "Http://www.springframework.org/schema/beans"
Xmlns:xsi = "Http://www.w3.org/2001/XMLSchema-instance"
Xmlns:context = "Http://www.springframework.org/schema/context"
XMLNS:AOP = "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"
Xsi:schemalocation = "Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
Http://www.springframework.org/schema/context
Http://www.springframework.org/schema/context/spring-context-2.5.xsd
HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-2.5.xsd ">
< Bean id = "Sessionfactory"