做了一个 aop的advisor,用的是before方式切面指定包下的所有webservice调用。如下类:
public class WebServiceAspectAdivice {

@Resource
    private WebServiceContext context;

public void execute() {
System.out.println("--------------------");
MessageContext ctx = context.getMessageContext();
HttpServletRequest request = (HttpServletRequest)ctx.get(AbstractHTTPDestination.HTTP_REQUEST);
request.setAttribute("code", "ok");
}

public WebServiceContext getContext() {
return context;
} public void setContext(WebServiceContext context) {
this.context = context;
}
}就是MessageContext ctx = context.getMessageContext();ctx为空指针
已确定context不为空了。
请问高手们是何原因

解决方案 »

  1.   

    Spring2.5后就可以使用Spring配置元素来配置AOP了,在一个<aop:config>里配置AOP的切点,Advice
    比单独配置Advice, BeanTarget, Bean, Advisor, Pointcut这么多xml元素方便很多,例如下面的代码就配置完一个切面了,非常方便,而且集中,好管理<aop:config>
        <aop:aspect class="任意一个普通的Bean的完全类名">
            <aop:pointcut id="mypc" expression=""/>
            <aop:before method="" pointcut-ref="mypc"/>
            <aop:after-returning method="" pointcut-ref="mypc"/>
        </aop:aspect>    <!-- 配置另一个切面 -->
        <aop:aspect class="">
            ....
        </aop:aspect>
    </aop:config>