3

JBossWS(ネイティブスタック)を使用してWebサービスを公開し、Springの依存性注入を利用しようとしています。これが私のコードのスクラブダウンバージョンです:

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にデプロイすると、正常に起動し、Springがクラスを事前インスタンス化していることがわかりますが、Webサービスへの呼び出しを発行すると、serviceEchoがNullPointerExceptionをスローしている間、endpointEchoは期待どおりに機能します。JBossWSがエンドポイントクラスをインスタンス化するとき、Spring構成を認識していないようです。JBossWSにSpringについて伝える簡単な方法はありますか?非常に細かい部分が欠けているか、これにすべて間違ってアプローチしているように感じます。何か案は?

4

1 に答える 1

2

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

于 2011-03-16T09:57:17.733 に答える