0

Apache CXF (CXFServlet) と Spring (ContextLoaderListener) を使用して小さなサンプル Web サービスを作成し、CXFServlet を登録して/URL をリッスンしました。そして、beans.xml で自分の Bean を宣言しています。

Tomcat で Web サービスを開始し、サービスの URL に移動すると、Web サービスの定義 (メソッド、エンドポイント、wsdl リンクなど) が表示されます。しかし問題は、wsdl リンクをクリックしても WSDL ファイルを取得できず、代わりに同じページに再帰的に転送されますが、そのたびに Web サービス アドレスの名前が追加されることです。

  1. ローカルホスト:8080/Test/accountEndpoint
  2. localhost:8080/Test/accountEndpointaccountEndpoint
  3. localhost:8080/Test/accountEndpointaccountEndpointaccountEndpoint

このサービスは、@WebService が Java インターフェイスと実装クラスにアノテーションを付けた「コード ファースト」サービスです。

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <display-name>Test</display-name>
    <servlet>
            <servlet-name>cxf</servlet-name>
            <display-name>cxf</display-name>
            <description>Apache CXF Endpoint</description>
            <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
    </servlet>

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

    <session-config>
            <session-timeout>60</session-timeout>
    </session-config>

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

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

ビーンズ.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:jaxws="http://cxf.apache.org/jaxws"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
    <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />

    <bean id="account" class=".....AccountImpl" />

    <jaxws:endpoint id="accountEndpoint" implementor="#account"
        address="accountEndpoint" />
</beans>

私が理解しているように、リンクをクリックすると、CXF は自動的に WSDL ファイルを生成して提供するはずなので、なぜそうならないのかわかりません。

4

1 に答える 1

2

先頭にスラッシュを付けて、次のようにアドレスを指定します。

<jaxws:endpoint id="accountEndpoint" implementor="#account"
    address="/accountEndpoint" />

申し訳ありませんが、変更を加えています。上記は正しくありません:

そうです、CXFServlet を の「デフォルト」サーブレット パス マッピングにマッピングすることで動作を複製できます。/自分で作業できる修正は、/*代わりにマッピングすることです。

<servlet-mapping>
        <servlet-name>cxf</servlet-name>
        <url-pattern>/*</url-pattern>
</servlet-mapping>
于 2012-12-21T22:03:21.467 に答える