4

SpringBeanAutowiringSupportを拡張することによって公開された私のWebサービスは、@Autowired依存関係を挿入できません。

Webサービスは正常にデプロイされ、@ WebMethodを呼び出すことはできますが、インジェクションが失敗したためにNullPointerExceptionが発生します。

XmlContactMapperSystem.out.println("Consructing XmlContactMapper...");のコンストラクター(@Autowiredとの依存関係の1つ)を配置しました。Webサービスをデプロイすると、デバッグ行が表示されるので、コンストラクターが呼び出されていることがわかります。しかし、何らかの理由で、XmlContactMapperのインスタンスがContactServiceImplxmlMapperプロパティに挿入されていません。

私が間違っていることについて何か考えはありますか?

使用中...

  • 春3.0.5.RELEASE
  • GlassFish 3.1
  • jaxws-rt 2.1.4

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee" 
         xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         id="WebApp_ID" version="3.0" metadata-complete="true">

    <display-name>contact-sib</display-name>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>           
            classpath:/config/bean-config.xml
        </param-value>
    </context-param>

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

    <servlet>
        <servlet-name>JaxWsEndpoint</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>JaxWsEndpoint</servlet-name>
        <url-pattern>/services/contact</url-pattern>
    </servlet-mapping>


</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="ContactService" 
            implementation="com.bb.sc.sib.contact.ContactServiceImpl" 
            url-pattern="/services/contact"/>

</endpoints>

bean-config.xml

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

    <context:component-scan base-package="com.bb.sc.sib.contact"/>
    <context:annotation-config/>

    <bean id="xmlMapper" class="com.bb.sc.sib.contact.XmlContactMapper"/>

</beans>

ウェブサービス

@WebService (endpointInterface="com.bb.sc.sei.contact.ContactService", serviceName="JaxWsContactService")
public class ContactServiceImpl extends SpringBeanAutowiringSupport implements ContactService {
    @Autowired
    private ContactComponent contactComponent;
    @Autowired
    private MapperFacade xmlMapper;

ロギング

INFO: 10:56:40.073 [admin-thread-pool-4848(419)] DEBUG o.s.w.c.s.SpringBeanAutowiringSupport - Current WebApplicationContext is not available for processing of ContactServiceImpl: Make sure this class gets constructed in a Spring web application. Proceeding without injection.
4

3 に答える 3

2

@Bijiが提案したように、これはContactServiceImplとContactComponentの間のロード順序の問題である可能性があると思います

通常、SpringBeanAutowiringSupportを拡張する必要がある理由は、Springコンテナーの外部でインスタンス化されたBeanがあるが、Springを介してその依存関係を解決する必要があるためです。

Glassfish + Metroを使用しているので、Metro Spring統合サポートを確認してください:http: //jax-ws-commons.java.net/spring/

このルートを使用すると、com.sun.xml.ws.transport.http.servlet.WSSpringServletは、Springコンテキストに関して適切なロード順序を処理する必要があります。

于 2012-10-19T23:11:34.830 に答える
1

リスナーの順序は重要です。のContextLoaderListener前に定義する必要がありますWSServletContextListener

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:wsContext.xml</param-value>
</context-param>

<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>
于 2015-03-23T13:16:50.160 に答える
0

Zeemeeがすでに述べたように、リスナー定義の順序は非常に重要です。さらに、Tomcat 8.0.26はそれ自体で順序を考慮していなかったため、追加する<absolute-ordering/>必要がありました。web.xml

于 2017-08-28T08:53:55.187 に答える