Announcement Announcement Module
Collapse
No announcement yet.
Configure Aspect using javaConfig Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Configure Aspect using javaConfig

    I am trying to create an Aspect advisor using the aop. I need to configure it using javaConfig and NOT using xml
    I have the following Aspect (taken form the Spring tutorial)

    Code:
    package org.try;
    
    import org.aspectj.lang.ProceedingJoinPoint;
    import org.aspectj.lang.annotation.Around;
    import org.aspectj.lang.annotation.Aspect;
    import org.springframework.core.Ordered;
    
    @Aspect
    public class ConcurrentOperationExecutor implements Ordered
    {
    
        private int order = 1;
    
        public int getOrder()
        {
            return this.order;
        }
    
        public void setOrder(int order)
        {
            this.order = order;
        }
    
        @Around("@annotation(org.try.Advised)")
        public Object doConcurrentOperation(ProceedingJoinPoint pjp)
            throws Throwable
        {
            System.out.println("IN ASPECT SUCCESS!!!!!!!!!!!!!!!!!!! " +  pjp.getSignature().getDeclaringTypeName() + " "  + pjp.getSignature().toLongString());
            return pjp.proceed();
    
        }
    
    }
    I am using javaConfig to configure all spring related Beans
    but I cant get the Aspect to be configured as an Advisor.
    my javaConfig:
    Code:
        @Bean
        public ConcurrentOperationExecutor concurrentOperationExecutor()
        {
            ConcurrentOperationExecutor coe = new ConcurrentOperationExecutor();
            coe.setOrder(1);
            return coe;
        }
    In the xml file I have the following tag:
    Code:
    <aop:aspectj-autoproxy/>
    I tried to put the configuration in the xml file this way:
    Code:
    <bean id="concurrentOperationExecutor"
                                    class="org.try.ConcurrentOperationExecutor">
                                    <property name="order" value="1" />
                    </bean>
    but it seems that the Advisor works but doesnt catch all annotated methods. It catches some annotated methods and it misses some others.
    I believe it has something to do with all the rest of the beans configured using javaconfig.

    We also have a regular transaction advisor using annotations that works without problems (using @SpringAdvisor) on the bean.

    Did anyone else try to use JavaConfig with Spring AOP and advisors?

  • #2
    Well!
    Thank you all
    i found the answer my self:
    Code:
        @Bean
        @SpringAdvice("@annotation(org.try.Advised)")
        public MethodInterceptor around() {
            return new MethodInterceptor() {
                public Object invoke(MethodInvocation mi) throws Throwable {
                    System.out.println("IN ASPECT SUCCESS!!!!!!!!!!!!!!!!!!! ");
                    return mi.proceed();
                }
            };
        }
    enjoy
    no other configuration is needed what so ever

    Comment

    Working...
    X