Announcement Announcement Module
Collapse
No announcement yet.
problem with pointcut="@annotation(..." Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem with pointcut="@annotation(..."

    Hi,

    I am fairly new to spring

    My dao interface
    Code:
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    
    public interface VehicleDao {
    	
    	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = VehicleException.class, readOnly = false)
    	public Vehicle addVehicle(String name, String subType,
    			NumberOfPassengers num) throws VehicleException;
    //other methods
    }
    I am having a exception translator to translate DataAccessException to my AppException
    Code:
    @Aspect
    public class ExceptionTranslator implements AfterAdvice{
        @AfterThrowing(throwing="e",pointcut="@annotation(org.springframework.transaction.annotation.Transactional)")
        public void rethrow( DataAccessException e ) throws VehicleException {
        	System.out.println("DAE:"+e.getRootCause());
    //my code
            throw new VehicleException();
        }
    But the rethrow method is not called.

    If I use my @AfterThrowing like:
    Code:
    @AfterThrowing(throwing="e",pointcut="execution(* *.add*(..))")
    instead of
    Code:
     @AfterThrowing(throwing="e",pointcut="@annotation(org.springframework.transaction.annotation.Transactional)")
    everythings working fine.

    Can anyone please explain me the reason behind this behaviour and how to solve this?

  • #2
    Instead of @annotation try @target...

    Comment


    • #3
      Thanks for the response.. but that doesnt work either...

      Code:
      @AfterThrowing(throwing="e",pointcut="@target(org.springframework.transaction.annotation.Transactional)")

      Comment


      • #4
        Why do you implement AfterAdvice you are using AspectJ so no need for that interface... Next to that please post your aop configuration...

        Comment


        • #5
          This is my application context:
          Code:
          <?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-2.0.xsd
          						http://www.springframework.org/schema/aop
          						http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
          						http://www.springframework.org/schema/tx
          						http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
          
          	<bean id="vehicleDao"
          		class="vehicle.dao.VehicleDaoJPAImpl">
          		<property name="entityManagerFactory"
          			ref="entityManagerFactory" />
          	</bean>
          
          	<bean id="entityManagerFactory"
          		class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
          		<property name="persistenceUnitName" value="vehicle" />
          	</bean>
          
          	<bean
          		class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
          
          	<bean
          		class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
          
          	<tx:annotation-driven transaction-manager="transactionManager" />
          
          	<bean id="jpaDialect"
          		class="org.springframework.orm.jpa.vendor.HibernateJpaDialect"
          		autowire="no" />
          
          	<bean id="transactionManager"
          		class="org.springframework.orm.jpa.JpaTransactionManager">
          		<property name="entityManagerFactory"
          			ref="entityManagerFactory" />
          		<property name="jpaDialect" ref="jpaDialect" />
          	</bean>
          
          	<bean class="vehicle.exception.util.ExceptionTranslator" />
          
          	<aop:aspectj-autoproxy />
          
          </beans>
          Am I missing something here?

          Comment


          • #6
            You have annotated your interfaces, you must annotate your implementing class. Annotations on the interfaces aren't inherited to the implementation. So I also expect you have transactional issues or will run into them soon...

            Comment


            • #7
              Thanks a ton, for the reply.

              Well, I had some transactional problems and thats why I have the annotations to the interface.

              I was giving this a thought. Transactions should be applied on my service layer. In case I want my DataAccessException to be translated to my AppException in the DAO layer, there is no point in where I can specify the pointcut for @transactional.

              And what is the best procedure to be followed? Translate the exceptions at dao layer or service layer?

              And also if you suggest to use it in my service layer, I t would be great if you can provide the way to solve the forthcoming transaction issues...

              Comment


              • #8
                You have to have the annotations on the implementing class, on the interface is not going to work (as you noticed with your after throws advice). I think the translation should happen between your data and service layer so after the call to your dao, that way your service remains free of dataacessexception handling.

                Also you are using annotations, if you where to use Spring 2.5 you could annotate your dao's with the @Repository and use that for your ExceptionTranslation filter.

                But the first thing to do is to move your annotations to your implementing classes.

                Comment


                • #9
                  Thanks for the help..

                  Comment

                  Working...
                  X