അനർഗള നിർഗള പ്രവാഹം
  • ബഹിർസ്പുരണങ്ങൾ
  • Note Book
  • Family History
  • ബഹിർസ്പുരണങ്ങൾ
  • Note Book
  • Family History
Search by typing & pressing enter

YOUR CART

6/14/2013 1 Comment

Spring AOP and Transaction Management

Step 1: declarations in applicationContext.xml

<?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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">


     <!-- SessionFactory is assumed to be defined -->
    <bean id="documentsDAO" class="com.feature.dao.DocumentsDAOImpl"  lazy-init="true">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean> 

    <bean id="documentsService" class="com.feature.service.DocumentsServiceImpl" lazy-init="true">
           <property name="dao" ref="documentsDAO"/>
    </bean>  
  

    <bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager" />    
  
    <aop:config>

        <aop:pointcut id="documentsServiceMethods" 
                                    expression="execution(* com.feature.service.DocumentsService.*(..))" />
        <aop:advisor advice-ref="txAdvice" pointcut-ref="documentsServiceMethods"/>

    </aop:config>

    <tx:advice id="txAdvice" transaction-manager="txManager">
        <tx:attributes>
        
    <tx:method name="*" propagation="REQUIRED"/>
        </tx:attributes>
    </tx:advice>
 </beans>

Step 2: Annotate the Class

package com.feature.service
import org.springframework.transaction.annotation.Transactional;
import com.feature.dao.DocumentsDAO;
import com.feature.entity.Document;
import com.feature.entity.Category ;

public class DocumentsServiceImpl implements DocumentsService {
    @Transactional
    private List<Document> getDocuments(Category category){
        DocumentsDAO dao = getDocumentsDAO();
        return dao.getDocuments(category);  
    }
}

NOTE: The @Transactional annotation can be applied to methods in any class - not necessarily a DAO
1 Comment
Mark Robertson link
11/15/2022 03:51:40 am

Along he upon will yard to. Box wish learn team her job feel. Key but learn eight beautiful front continue kind.

Reply



Leave a Reply.

    Archives

    July 2016
    October 2013
    July 2013
    June 2013

    Categories

    All

    RSS Feed

Powered by Create your own unique website with customizable templates.