JAX WS webservice does not take spring bean from applicationcontext, hence throws null pointer exception

后端 未结 6 1758
终归单人心
终归单人心 2021-01-18 07:55

Hi I have got the webservice up and running , i have used jax ws. I have used Spring to be able to use beans with Autowired and stuff that spring gives like property value i

相关标签:
6条回答
  • 2021-01-18 08:42

    It is answered here. Ultimately nothing worked other than adding below code to service impl.

        @PostConstruct
    public void init() {
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
    }
    
    0 讨论(0)
  • 2021-01-18 08:43

    Your TestService (which is annotated with @WebService) should extend "SpringBeanAutowiringSupport" class to kick start spring binding.

    Please have a look at the duffmo mentioned points as well.

    0 讨论(0)
  • 2021-01-18 08:46

    I think it's more likely that your Spring context has not be loaded and made available to the web service. How have you done that?

    You should have a ContextLoaderListener configured in the web.xml for the WAR in which the web service is deployed. Did you tell it where to load the Spring context? Are you using component scan?

    http://renidev.wordpress.com/2009/02/02/how-to-use-springs-context-component-scan-and-annotation/

    0 讨论(0)
  • 2021-01-18 08:58

    No Need to use ApplicationContext as well, if you do the following things

    1. Annotate your service class with @Service
    2. Service class should extends "SpringBeanAutowiringSupport".

    Please have a look at the following snippet.

    @org.springframework.stereotype.Service
    @javax.jws.WebService (endpointInterface="a.b.c.MyPort", 
                targetNamespace="http://a.b.co.in/Retail/MyService/V1", 
                serviceName="MyService", 
                portName="MyServicePort", 
                wsdlLocation="wsdl/MyService.wsdl")
    public class MyServiceBindingImpl extends org.springframework.web.context.support.SpringBeanAutowiringSupport{
    
    0 讨论(0)
  • 2021-01-18 09:01

    I got the same issue, to resolve it I started the jaxws listener after the spring listener:

        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
         <listener>
            <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
        </listener>
    

    Hope it helps

    0 讨论(0)
  • 2021-01-18 09:02

    You misses the configuration for webservice inject. So put more inside the web.xml

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
    </listener>
    

    Please don't forget the order. Because you need to init the bean for the autowired field first

    Thanks

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