Spring AOP not working in Tomcat and tcserver

I have an aspect that works great when I run it from unit test or through a standalone application. However, when I run it as part of a web application and host it on Tomcat, aspects do not apply.

My aspect looks like

public class MyAspect {

    @Around("within(com.service..*)")
    public Object doLogging(ProceedingJoinPoint pjp) throws Throwable {
        //do something
        Object obj = pjp.proceed();
        //do something else
        return obj;
    }

}
+3
source share
3 answers

I can solve it. The reason was that this aspect was handled by the web application context, rather than the global application context, so I have to restructure a couple of things. I have described the steps in detail here

@seanizer Spring . , com.service. .

+3

: , , . , this .

Spring AOP, . Spring AOP pointcut execution. within , , within AspectJ (Spring AOP point point AspectJ, AspectJ). ( Maven Ant) Load-Time-Weaving.

, @Aspect.

+1

<context:component-scan base-package="com.*" />
<mvc:annotation-driven/>
<aop:aspectj-autoproxy />   

to servlet-mvc.xml?

0

Source: https://habr.com/ru/post/1773180/


All Articles