CXF JAXRS MessageContext Injection in "in Interceptor"

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

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?



source to share

1 answer

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

to your cxf config file:

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


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;

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


Consider also this link for documentation:



All Articles