2

シンプルな Spring MVC Web アプリケーションを作成し、 JAX-WS コモンズ RI実装を使用して SOAP ベースの JAX-WS サービスとしてサービスを公開しようとしました。

アプリケーションを Tomcat 7 にデプロイした後、Web サービスにアクセスしようとすると、404 Not Found: Invalid Request というメッセージが表示されます。以下は私の構成です。これを解決するのに親切に助けてください。

web.xml

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

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes SOAP Web Service requests -->
    <servlet>
        <servlet-name>jaxws-servlet</servlet-name>
        <servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jaxws-servlet</servlet-name>
        <url-pattern>/ws/*</url-pattern>
    </servlet-mapping>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

WEB-INF/spring/appServlet/servlet-context.xml

    <beans:bean id="customerService" class="com.home.service.CustomerService" />

    <!-- Web Service definition -->
    <beans:bean id="customerWS" class="com.home.ws.CustomerWS">
        <beans:property name="customerService" ref="customerService" />
    </beans:bean>

    <wss:binding url="/ws/CustomerServ">
        <wss:service>
            <ws:service bean="#customerWS" />
        </wss:service>
    </wss:binding>

CustomerWS.java

@WebService
@SOAPBinding(style = Style.DOCUMENT, use = Use.LITERAL)
public class CustomerWS {

    private CustomerService customerService;

    @WebMethod
    public Customer read(long id) {
        return customerService.read(id);
    }

    public void setCustomerService(CustomerService customerService) {
        this.customerService = customerService;
    }
}

CustomerService.java

@Service
public class CustomerService {
    public Customer read(long id) {
        Customer cust = null;
        System.out.println("CustomerService.read invoked");

        return cust;
    }
}

pom.xml - jaxws-spring の依存関係を含めました

    <dependency>
        <groupId>org.jvnet.jax-ws-commons.spring</groupId>
        <artifactId>jaxws-spring</artifactId>
        <version>1.9</version>
    </dependency>

アプリケーションのビルドまたはデプロイ中にエラーは発生しません。URL にアクセスしても、サーバー ログ ファイルにエラーは表示されません。ただし、ブラウザにはメッセージが表示されます - 404 Not Found: Invalid Request

私が試しているURLは -http://localhost:8080/crrs/ws/CustomerServ?wsdl

HomeController にアクセスすると、問題なく動作します。ホームページが期待どおりに読み込まれます。

どんな助けにも感謝します。前もって感謝します。

4

2 に答える 2

2

私は同じことをしようとしています。私のコードはほぼ同じです。@Service の代わりに @Name と @Inject を使用しているだけです。

クラスに追加さextends SpringBeanAutowiringSupportれたばかりで、機能しています@WebService

于 2013-10-31T21:58:07.277 に答える
1

web.xml のサーブレット マッピングが原因のようです。

<servlet-mapping>
    <servlet-name>jaxws-servlet</servlet-name>
    <url-pattern>/ws/*</url-pattern>
</servlet-mapping>

[...]

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

DispatcherServletという名前のスプリングは、appServletの後のすべての URL を処理します。http://localhost:8080/crrshttp://localhost:8080/crrs/ws/CustomerServ?wsdl

URL パターンにWSSpringServlet到達できません。

于 2015-01-22T12:38:36.717 に答える