CXF JAXRS MessageContext Injection in "in Interceptor"

I am trying to inject MessageContext into Interceptor with phase as READ as follows

@Context
org.apache.cxf.jaxrs.ext.MessageContext.MessageContext messageContext;

      

But this is not initialized and remains null. Is it possible to inject org.apache.cxf.jaxrs.ext.MessageContext.MessageContext in the Interceptor?

thank

+3


source to share


1 answer


You may need to add <aop:scoped-proxy/>

to your cxf config file:

<jaxrs:server id="example" address="/">
    <jaxrs:serviceBeans>
         <bean class="org.apache.cxf.systest.jaxrs.CustomerService">
              <aop:scoped-proxy />
         </bean>
    </jaxrs:serviceBeans>
</jaxrs:server>

      

Also you need to create a setter method for your messageContext (this should be in your service class - here it is "org.apache.cxf.systest.jaxrs.CustomerService"):



private MessageContext messageContext;

@Context
public void setMessageContext(MessageContext messageContext) {
    this.messageContext = messageContext;
}

      

Consider also this link for documentation:
http://cxf.apache.org/docs/jaxrs-services-configuration.html#JAXRSServicesConfiguration-FromSpring

+2


source







All Articles