I'm trying to get Apache CXF JAX-RS services working with Spring AOP. I've created a simple logging class:
public class开发者_如何学编程 AOPLogger {
public void logBefore(){
System.out.println("Logging Before!");
}
}
My Spring configuration (beans.xml):
<aop:config>
<aop:aspect id="aopLogger" ref="test.aop.AOPLogger">
<aop:before method="logBefore" pointcut="execution(* test.rest.RestService.*(..))"/>
</aop:aspect>
</aop:config>
<bean id="aopLogger" class="test.aop.AOPLogger"/>
I always get an NPE in RestService when a call is made to a Method getServletRequest(), which has:
return messageContext.getHttpServletRequest();
If I remove the aop configuration or comment it out from my beans.xml, everything works fine.
All of my actual Rest services extend test.rest.RestService (which is a class) and call getServletRequest(). I'm just trying to just get AOP up and running based off of the example in the CXF JAX-RS documentation. What am I doing wrong?
You just need to have your resource class implementing some simple interface with a method
@Context void setMessageContext(MessageContext mc) {}
this will enable the CXF SpringAOPHelper to discover the method
精彩评论