2013-02-28 16 views
7

私はApache CXFとTomcatのかなり新しいです。私は単純なWebサービスを構築し、それをTomcatにデプロイしようとしています。以下は私のweb.xmlです 私のブラウザを使って 'services'フォルダにアクセスしようとすると、No services were foundというメッセージが表示されます。私はJava Webサービスクライアントを作成しようとしましたが、サービスを見つけることもできません。これで何が間違っているのでしょうか?Apache CXFとtomcat

<?xml version="1.0" encoding="UTF-8"?> 
<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"> 
    <display-name>Sample web service provider</display-name> 
    <listener> 
     <!-- For Metro, use this listener-class instead: 
      com.sun.xml.ws.transport.http.servlet.WSServletContextListener --> 
     <listener-class> 
       org.springframework.web.context.ContextLoaderListener 
     </listener-class> 
    </listener> 
    <!-- Remove below context-param element if using Metro --> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value> 
       classpath:META-INF/cxf/cxf.xml 
     </param-value> 
    </context-param> 
    <servlet> 
     <servlet-name>WebServicePort</servlet-name> 
     <!-- For Metro, use this servlet-class instead: 
      com.sun.xml.ws.transport.http.servlet.WSServlet --> 
     <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>WebServicePort</servlet-name> 
     <url-pattern>/services/*</url-pattern> 
    </servlet-mapping> 
    <session-config> 
     <session-timeout>60</session-timeout> 
    </session-config> 
</web-app> 

答えて

6

これは、アプリケーションに公開されているサービスがないことを意味します。あなたのweb.xmlは正しいと思われますが、私はあなたの春の設定を見逃してしまいました。例えばのために、あなたのweb.xmlであなたの春の設定の場所を追加します。:

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

をまた、あなたのWebサービスインターフェイスを実装して、春applicationContext.xml設定ファイルのCXFエンドポイントとして、それを公開するクラスを作成する必要があります。例えば:

<bean id="candidateImpl" class="some.pckg.CandidateImpl"/> 

<jaxws:endpoint id="candidateEndpoint" 
       implementor="#candidateImpl" 
       address="/Candidate" 
     /> 

についてあなたのCandidateImplクラスは@WebService注釈を持っている必要があります。例えばのために:あなたは正しく、すべてをやった場合

@WebService(targetNamespace = "http://something.com/ws/candidate", 
     portName = "CandidateService", 
     serviceName = "Candidate", 
     endpointInterface = "some.pckg.types.CandidateService", 
     wsdlLocation = "WEB-INF/wsdl/CandidateService.wsdl") 
public class CandidateImpl implements CandidateService { 
    //Implementation of all methods from CandidateService. 
} 

あなたは下の1つのサービス利用可能であることを確認する必要があります

http(s)://whateverhost.com:<somePort>/SomeContextPath/services 

そして、あなたは、このようにWSDLファイルを得ることができる必要があります:

http(s)://whateverhost.com:<somePort>/SomeContextPath/services/Candidate?wsdl 

も参照してください:

1

あなたはこの仕事をするために、スプリングの設定ファイルの場所を設定する必要があります。以下のように設定することができます。

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

web.xmlにサーブレットを設定する必要があります。以下の例。

ここでWEB-INFフォルダの下にspring-ws-servlet.xmlという名前のファイルを定義する必要があります。 spring-ws-servlet.xmlの内容の例の下に、Webサービスの実際の設定が含まれています。これはもちろん、あなたのロジックに依存します。これにより

<?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:jaxws="http://cxf.apache.org/jaxws" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.2.xsd 
     http://cxf.apache.org/jaxws 
     http://cxf.apache.org/schemas/jaxws.xsd"> 

    <context:component-scan base-package="com.sample.service"/> 

    <!-- JAX-WS Service Endpoint --> 
    <bean id="personImpl" class="com.sample.service.impl.PersonServiceImpl"/> 

    <jaxws:endpoint id="personEndpoint" 
        implementor="#personImpl" 
        address="/person"> 
     <jaxws:properties> 
      <entry key="schema-validation-enabled" value="true"/> 
     </jaxws:properties> 
    </jaxws:endpoint> 
    <!-- JAX-WS Service Endpoint End--> 
</beans> 

は、あなたがこれは、この記事から取られhttp://localhost:8080/services/person?wsdl

の下で、Webサービスにアクセスすることができます。これは、IntelliJのアイデアや春

https://aldavblog.wordpress.com/2015/01/22/creating-a-web-service-from-scratch-using-spring-maven-apache-cxf/

+0

このリンクは質問に答えるかもしれないが、ここでは答えの重要な部分が含まれており、参照のためのリンクを提供した方がよいとCXFサービスの作成についてのチュートリアルです。リンクされたページが変更された場合、リンクのみの回答は無効になります。 – tbodt

+0

[OK]をクリックして、不足している情報で回答を更新しました。それが役に立てば幸い。 –