【问题标题】:Apache CXF REST Services w/ Spring AOP带有 Spring AOP 的 Apache CXF REST 服务
【发布时间】:2017-12-09 12:24:49
【问题描述】:

我正在尝试让 Apache CXF JAX-RS 服务与 Spring AOP 一起工作。我创建了一个简单的日志记录类:

public class AOPLogger {

    public void logBefore(){
        System.out.println("Logging Before!");
    }

}

我的 Spring 配置(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"/>

当调用方法 getServletRequest() 时,我总是在 RestService 中得到 NPE,该方法具有:

return messageContext.getHttpServletRequest();

如果我从 beans.xml 中删除 aop 配置或将其注释掉,一切正常。

我所有的实际 Rest 服务都扩展了 test.rest.RestService(这是一个类)并调用 getServletRequest()。我只是想根据 CXF JAX-RS 文档中的示例启动并运行 AOP。我做错了什么?

【问题讨论】:

    标签: aop cxf jax-rs spring-aop


    【解决方案1】:

    你只需要让你的资源类用一个方法实现一些简单的接口

    @上下文 无效 setMessageContext(MessageContext mc) {}

    这将使 CXF SpringAOPHelper 能够发现方法

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-27
      • 2015-09-03
      • 1970-01-01
      • 2016-05-30
      • 1970-01-01
      • 2020-05-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多