Answer the question
In order to leave comments, you need to log in
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>
@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");
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question