Spring AOP (Aspect) Not executing

前端 未结 6 683
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 08:18

I ams using Spring 2.5.6, asm 1.5.3, aspectjrt/aspectjweaver 1.6.1, cglib 2.1_3 In my Web based Spring application I have following class:

package uk.co.txttools         


        
6条回答
  •  春和景丽
    2021-02-05 08:53

    I'm not sure if I did it properly but for me what solved it was adding @Component to the "Aspect'ed" class -

    @Aspect
    @Component
    public class PerformanceLogger {
    
        private Logger logger = LoggerFactory.getLogger(this.getClass());
    
        @Around("within(com.something.rest.service..*)")
        public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
            long start = System.currentTimeMillis();
            Object retVal = pjp.proceed();
            long end = System.currentTimeMillis();
            logger.debug(pjp.getSignature().toShortString() + " Finish: " + (end - start) + "ms");
            return retVal;
        }
    }
    

    (And just to close the loop - if you are using annotation based, don't forget adding @EnableAspectJAutoProxy to your Config class.

    @EnableAspectJAutoProxy
    

提交回复
热议问题