Spring configuration transactions at the DAO Layer and service layer

Source: Internet
Author: User
Tags aop
"Reprinted from Http://www.blogjava.net/hk2000c/archive/2007/11/01/157508.html"
"Thank the original author: hk2000c"
Spring implements declarative transaction management through AOP. The spring transaction agent is typically set up through Transactionproxyfactorybean. We need a target object wrapped in the transaction agent. This target object is typically a bean of a normal Java object. When we define Transactionproxyfactorybean, we must provide an associated Platformtransactionmanager reference and transaction attributes. The transaction attribute contains the transaction definition described above.
Platformtransactionmanager:
Hibernatetransactionmanager needs a sessionfactory reference.
Jtatransactionmanager
A To place a transaction on the DAO Layer:
Java code    <!-hibernateTransactionManager-->   <bean id= "TransactionManager"           class= " Org.springframework.orm.hibernate3.HibernateTransactionManager ">           <property name= "Sessionfactory" >                  <ref local= "Sessionfactory"  />           </property>   </bean>   <!-dao Layer Interface Implementation-->    <bean id= "Companydaotarget"           class= " Com.vstsoft.querycompany.dao.impl.CompanyDAOImpl ">           <property name= "Sessionfactory" >                  <ref local= "SessionfactoRy " />          </property>   </bean>    <!-spring to the DAO layer's transaction Agent-->   <bean id= "Companydaoproxy"            class= "Org.springframework.transaction.interceptor.TransactionProxyFactoryBean" >          <property name= "TransactionManager" >                  <ref  Bean= "TransactionManager"  />          </property>           <property name= "target" >                  <ref local= " Companydaotarget " />          </property>    &NBSP;&NBSP;&NBSP;&NBSP;   <property name= "Transactionattributes" >                  <props>                  <prop key= "insert*" >PROPAGATION_ required</prop>                  <prop key= "delete*" >PROPAGATION_REQUIRED</prop>                  <prop key= "find*" >                 propagation_required, readonly                 </ prop>                 </ props>          </property>   </bean>   <!-Business layer Interface implementation, Inject DAO into service-->   <bean name= "Companymanagetarget"            class= "Com.vstsoft.querycompany.service.impl.CompanyManageTarget" >           <property name= "Companydao" >                  <ref bean= "CompanyDAOProxy"  / >          </property>   </bean>    <!-spring to service layer agent-->   <bean id= "Companymanageproxy"            class= "Org.springframework.aop.framework.ProxyFactoryBean" >           <property name= "Proxyinterfaces" >           &nBsp;      <value>com.vstsoft.querycompany.service.companymanage</value >          </property>           <property name= "Target" >                  <ref bean= "Companymanagetarget"  />          </property>   </bean>   <!- Configure struts access, inject the service layer into the action-->   <bean name= "/company"            class= "Com.vstsoft.querycompany.web.action.CompanyAction"  singleton= "false" >           <property name= "Companymanage" >                 <ref local= " Companymanageproxy " />          </property>   </bean>  

Two The transaction is placed at the service level:
Java code    <!-jtaTransactionManager-->   <bean id= "Jtatransactionmanager"            class= " Org.springframework.transaction.jta.JtaTransactionManager " />   <!-dao layer Interface Implementation-->    <bean id= "Companydaotarget"           class= " Com.vstsoft.querycompany.dao.impl.CompanyDAOImpl ">           <property name= "Sessionfactory" >                  <ref local= "Sessionfactory"  />           </property>   </bean>   <!-spring proxy-->  for DAO layer   <bean id= "Companydaoproxy"           class= " Org.springframework.aop.framework.ProxyFactoryBean ">          <property name= "Proxyinterfaces" >                  <value> com.vstsoft.querycompany.dao.companydao</value>  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.