我的应用程序通常有效,但我在访问MessageContext时遇到问题。 无论在实例变量或setter方法上使用@Context,MessageContext始终为null。
注意:我的界面已生成且无法更改。我需要每个调用新的CarApiEntryPoint对象(即我希望CarApiEntryPoint作为原型)。如果我删除aop:scoped-proxy,则会填充MessageContext,但我会获得Singleton实例
在我的beans.xml中
<jaxrs:server address="/rs">
<jaxrs:serviceBeans>
<ref bean="carBean"/>
</jaxrs:serviceBeans>
</jaxrs:server>
<bean id="cartBean" class ="com.xyz.CarApiEntryPoint" scope="prototype">
<aop:scoped-proxy proxy-target-class="true"/>
</bean>
类
import org.apache.cxf.jaxrs.ext.MessageContext;
public class CarApiEntryPoint implements CarApi{
@Context MessageContext messageContext;
.......// Overriding methods from CarApi
}
@Path("/V1")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public interface CarApi {
@POST
@Path("/cars/{carId}/")
//methods....
}
请提供宝贵的建议,告诉我我做错了什么。