복붙노트

[SPRING] JAX WS webservice는 applicationcontext에서 스프링 빈을 가져 가지 않으므로 null 포인터 예외가 발생합니다.

SPRING

JAX WS webservice는 applicationcontext에서 스프링 빈을 가져 가지 않으므로 null 포인터 예외가 발생합니다.

안녕 나는 webservice를 가지고 있고 실행, 나는 jax ws를 사용했습니다. Spring을 사용하여 Autowired가있는 bean을 사용할 수 있고 spring은 applicationContext.xml에 속성 값 주입과 같은 기능을 제공합니다.

아래 봄 applicationcontext.xml 항목이 있습니다.

<context:component-scan base-package="com.mybeans.service" />      
<bean  id="myProperty" class="com.mybeans.service.MyBeanProperty"
p:Size="BIG">
</bean>

웹 서비스 엔드 포인트 클래스에서, 나는 해냈다 :

@Autowired private MyBeanProperty myProperty;

그리고 나는 방법이있다 :

public String getSize() {

return myProperty.getSize();

}

불행히도 내가 메서드를 호출하면 어떤 값도 얻지 못하고 nullpointerexception을 던진다.

추신 : 나는 webservice의 wsdl을 실행하기 위해 soapUI를 사용하고 메소드를 호출했습니다.

빈에 의해 생성되기 전에 webservice가 실행됩니까 ??

더프 모에

네, applicationContext에서 컴포넌트 스캔을 사용했습니다. 그리고 web.xml에 아래와 같이 context loader listener가 있습니다. 제발 .. 도와주세요.

다음은 코드를 사용한 완전한 코드 설명입니다.

JAX-WS와 Spring을 사용 중이며 Tomcat 7에서 실행해야하는 몇 가지 WebServices를 설정하려고합니다. 따라서 메이븐 (Maven)을 빌드 도구로 사용하고 있습니다.

<dependencies>
   <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>3.0.5.RELEASE</version>
   </dependency>

     <dependencies>
    <dependency>
      <groupId>com.sun.xml.ws</groupId>
      <artifactId>jaxws-rt</artifactId>
      <version>2.1.3</version>
    </dependency>

    </dependencies>

내 서비스 클래스는 com.test.services에 있으며 TestService 및 HelloWorldService라는 이름을 가지며 다음과 같이 표시됩니다.

package com.test.services;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService( name = "Test", serviceName = "TestService" )
public class TestService {

  @WebMethod
  public String getTest() {
    return "Test";
  }

}

이것은 내 web.xml입니다.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <display-name>toolbox</display-name>
  <description>testing webservices</description>
  <listener>
    <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>jaxws-servlet</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>jaxws-servlet</servlet-name>
    <url-pattern>/testservice</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>jaxws-servlet</servlet-name>
    <url-pattern>/helloworldservice</url-pattern>
  </servlet-mapping>
  <session-config>
    <session-timeout>10</session-timeout>
  </session-config>
</web-app>

그리고 이것은 내 sun-jaxws.xml입니다.

<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
    <endpoint
        name="jaxws-servlet"
        implementation="com.test.services.TestService"
        url-pattern="/testservice"/>
    <endpoint
        name="jaxws-servlet"
        implementation="com.test.services.HelloWorldService"
        url-pattern="/helloworldservice" />
</endpoints>

이것은 훌륭하게 작동하며 브라우저에서 [http : // localhost : 8080 / toolbox / testservice [url] http : // localhost : 8080 / toolbox / helloworldservice [/ url]을 지정하여 서비스에 액세스 할 수 있습니다. ]. 그러나 Spring 지원은 분명히 활성화되지 않습니다.

HelloWorldService를 사용할 수있는 다음을 시도했습니다. web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <display-name>toolbox</display-name>
  <session-config>
    <session-timeout>30</session-timeout>
  </session-config>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
</web-app>

및 applicationContext.xml :

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
  xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:task="http://www.springframework.org/schema/task"
  xsi:schemaLocation="
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
  <context:component-scan base-package="com.test.services" />
  <bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter">
    <property name="baseAddress" value="http://localhost:8080/" />
  </bean>
 </beans>

또한 두 서비스 클래스에 @Service 주석을 추가했습니다. 이전에 언급했듯이, 이것은 알파벳순으로 첫 번째 웹 서비스 만 게시하므로 HelloWorldService입니다. 또한 서비스는 이제 [url] http : // localhost : 8080 / toolbox / helloworldservice [/ url]이 아닌 [url] http : // localhost : 8080 / [/ url]로 사용할 수 있으므로 URL을 변경합니다. Tomcat의 로깅은 Spring Context가 두 클래스 모두를 Spring 빈으로로드한다는 것을 보여준다. 두 서비스를 계속 사용하면서 Spring 지원을 활성화하는 방법에 대한 아이디어 나 제안이 있습니까?

해결법

  1. ==============================

    1.여기에 답이 있습니다. 궁극적으로 서비스 impl에 코드를 추가하는 것 외에는 아무 것도 작동하지 않습니다.

    여기에 답이 있습니다. 궁극적으로 서비스 impl에 코드를 추가하는 것 외에는 아무 것도 작동하지 않습니다.

        @PostConstruct
    public void init() {
        SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
    }
    
  2. ==============================

    2.다음과 같은 일을한다면 ApplicationContext를 사용할 필요가 없다.

    다음과 같은 일을한다면 ApplicationContext를 사용할 필요가 없다.

    다음 스 니펫을 살펴보십시오.

    @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{
    
  3. ==============================

    3.나는 같은 문제를 해결하기 위해 봄 청취 후 jaxws 청취자를 시작했다.

    나는 같은 문제를 해결하기 위해 봄 청취 후 jaxws 청취자를 시작했다.

        <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>
    

    희망이 도움이된다.

  4. ==============================

    4.TestService (@WebService로 주석 첨부 됨)는 스프링 바인딩 시작을 위해 "SpringBeanAutowiringSupport"클래스를 확장해야합니다.

    TestService (@WebService로 주석 첨부 됨)는 스프링 바인딩 시작을 위해 "SpringBeanAutowiringSupport"클래스를 확장해야합니다.

    더프 모도 언급 한 점을 참고하십시오.

  5. ==============================

    5.Spring 컨텍스트가로드되지 않고 웹 서비스에서 사용 가능할 가능성이 더 높다고 생각합니다. 어떻게 한거야?

    Spring 컨텍스트가로드되지 않고 웹 서비스에서 사용 가능할 가능성이 더 높다고 생각합니다. 어떻게 한거야?

    웹 서비스가 배포되는 WAR에 대해 web.xml에 ContextLoaderListener가 구성되어 있어야합니다. Spring 컨텍스트를로드 할 위치를 알려 주셨습니까? 구성 요소 검사를 사용하고 있습니까?

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

  6. from https://stackoverflow.com/questions/12555707/jax-ws-webservice-does-not-take-spring-bean-from-applicationcontext-hence-throw by cc-by-sa and MIT license