JAX-WS WebServiceContext remains null (Annotation Injection Fails)

前端 未结 1 1930
情深已故
情深已故 2021-01-14 04:39

I\'ve tried deploying my app to both Tomcat 6 with Metro/Jersey and Glassfish 3.1.2, but accessing the WebServiceContext resource always causes a null pointer exception,

相关标签:
1条回答
  • 2021-01-14 05:24

    The difference is that the default GlassFish implementation is a JAX-WS SOAP-based web service. For a JAX-RS web service, you should use the following annotation to inject the context.

     @Context 
     private ServletContext sc;
    

    There are other types that you can use @Context annotation to inject, such as UriInfo, HttpHeaders. Please see Jersey documentation for details. WebServiceContext and MessageContext are JAX-WS objects that have no meaning in the JAX-RS context.

    0 讨论(0)
提交回复
热议问题