D
D
Daniil Miroshnichenko2016-11-02 03:44:06
Java
Daniil Miroshnichenko, 2016-11-02 03:44:06

How to attach an aspect to a class from a third-party jar?

The project uses Spring 3. There was a need to hang an aspect on the org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#handle method. This is a spring class, which naturally lies not in my project, but in jar. It is used in org.springframework.web.servlet.DispatcherServlet while processing requests to my spring rest mvc.
Here is the configuration:

<bean id="contextAspect" class="com.eightbitlab.spring3rest.config.ContextAspect"/>
<aop:aspectj-autoproxy proxy-target-class="true"/>
    <aop:config>
        <aop:aspect ref="contextAspect">
            <aop:pointcut id="contextPointcut" expression="execution (* org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handle(..))"/>
            <aop:around method="around" pointcut-ref="contextPointcut"/>
        </aop:aspect>
    </aop:config>

Here is the aspect:
@Aspect
public class ContextAspect {
    public void around(ProceedingJoinPoint joinPoint) throws Throwable {
        Logger.getAnonymousLogger().info("start aspect");
        Object proceeded = joinPoint.proceed();
        Logger.getAnonymousLogger().info("end aspect");
    }
}

If you try to hang the same aspect on one of my classes, then everything works out. Apparently the problem is that the class on which I'm trying to assign an aspect is in another jar...
Thanks in advance for your help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question