2011-03-14 8 views
3

JBossWS(ネイティブスタック)を使用してWebサービスを公開しようとしており、Springの依存関係注入を利用しています。JBossWSのスプリング設定

のweb.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" 
    version="2.4"> 

    <display-name>Test Service</display-name> 

    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
      /WEB-INF/applicationContext.xml 
     </param-value> 
    </context-param> 

    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <servlet>  
     <servlet-name>EndpointService</servlet-name> 
     <servlet-class>com.blah.webservice.EndpointService</servlet-class> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>EndpointService</servlet-name> 
     <url-pattern>/*</url-pattern> 
    </servlet-mapping> 
</web-app> 

applicationContext.xmlを:

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:aop="http://www.springframework.org/schema/aop" 
     xmlns:tx="http://www.springframework.org/schema/tx" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation=" 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"> 

    <context:spring-configured /> 
    <context:load-time-weaver /> 
    <context:annotation-config /> 

    <context:component-scan base-package="com.blah.webservice" /> 
</beans> 

EndpointService.java

package com.blah.webservice; 

import javax.jws.WebMethod; 
import javax.jws.WebService; 
import javax.jws.soap.SOAPBinding; 

import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Service; 

@Service 
@WebService 
@SOAPBinding(parameterStyle=SOAPBinding.ParameterStyle.BARE) 
public class EndpointService { 

    private TestService testService; 

    public EndpointService() {} 

    @Autowired 
    public EndpointService(TestService testService) { 
     this.testService = testService;   
    } 

    @WebMethod 
    public String endpointEcho(String echo) { 
     return echo; 
    } 

    @WebMethod 
    public String serviceEcho(String echo) { 
     return testService.serviceEcho(echo); 
    } 
} 
ここに私のコードのダウンスクラブバージョンがあります

TestService.java:

package com.blah.webservice; 

import org.springframework.stereotype.Service; 

@Service 
public class TestService { 

    public TestService() {} 

    public String serviceEcho(String echo) { 
     return echo; 
    } 
} 

私はこれを構築し、JBossへのデプロイする場合、それがうまく起動し、私は春が私のクラスを事前にインスタンス化されて見ることができますが、私は、Webサービスの呼び出しを発行したときserviceEchoがNullPointerExceptionをスローしている間は、endpointEchoは正常に動作します。 JBossWSがエンドポイントクラスをインスタンス化するとき、私のSpring設定についてはわかりません。 SpringについてJBossWSに伝える簡単な方法はありますか?私は非常に細かいディテールを見逃しているように感じます。あるいは、私はこのすべてに間違っています。何か案は?

答えて

2

サービスは、autowiringサポートを利用できるようにSpringBeanAutowiringSupportを拡張する必要があります。

+0

私はそれを試みました。 testServiceを呼び出そうとしても、まだNullPointerExceptionが発生しています。 autowiringが行われているようですが、間違ったコンテキストで起きている可能性があります。 – bhinks

+0

だから私はもう一度これを試しました(3回目の魅力はありますか?)、それは動作しているようです。私は@Autowiredアノテーションをエンドポイントクラスのコンストラクタから個々のプロパティ宣言に移しました。そして今私は揺れ動いています。ありがとう! – bhinks

関連する問題