JAX-WS Java Webアプリケーション統合の例

多くの場合、JAX-WSは常にJava Webアプリケーションの一部です。ここでは、JAX-WSをJava Webアプリケーションに簡単に統合する方法を示します。

1.プロジェクトフォルダ

まず、このプロジェクトのフォルダ構造を見直します。

jax-ws-web-application-example、title = "jax-ws-web-application-example" -1 "、width = 301、height = 384]

2. Webサービス

スーパーシンプルなWebサービス。コードは自明です。

ファイル:Hello World.java

package com.mkyong.ws;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public class HelloWorld{

    @WebMethod(operationName="getHelloWorld")
    public String getHelloWorld(String name) {
        return "Hello World JAX-WS " + name;
    }

}

3. Webサービスデプロイメント記述子(sun-jaxws.xml)

`sun-jaxws.xml`という名前のWebサービスデプロイメント記述子を作成します。

File: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="HelloWorldWs"
      implementation="com.mkyong.ws.HelloWorld"
      url-pattern="/hello"/>
</endpoints>

4. Webアプリケーションデプロイメント記述子(web.xml)

標準の `web.xml`では、

  1. 定義する

"com.sun.xml.ws.transport.http.servlet.WSServletContextListener`"をリスナークラスとして使用します。

  1. "com.sun.xml.ws.transport.http.servlet.WSServlet`"をユーザー定義として定義します.

Webサービス(hello)サーブレット。

File:web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app__2__3.dtd" >

<web-app>
    <display-name>Archetype Created Web Application</display-name>

    <listener>
        <listener-class>
            com.sun.xml.ws.transport.http.servlet.WSServletContextListener
                </listener-class>
    </listener>
    <servlet>
        <servlet-name>hello</servlet-name>
        <servlet-class>
            com.sun.xml.ws.transport.http.servlet.WSServlet
                </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>hello</servlet-name>
        <url-pattern>/hello</url-pattern>
    </servlet-mapping>

</web-app>

5.完了

JAX-WSとWebアプリケーションの統合が行われます。それを展開し、URL経由でアクセスします。 http://localhost:8080/WebServicesExample/hello

jax-ws-web-application-example、title = "jax-ws-web-application-example" -2」、幅= 640、高さ= 382]

ソースコードをダウンロードする

ダウンロードする - JAX-WS-Integrate-WebApplication-Example.zip (7KB)

リファレンス

  1. リンク://webservices/jax-ws/deploy-jax-ws-web-services-on-tomcat/[How to

TomcatにJAX-WSをデプロイする]。リンク://webservices/jax-ws/jax-ws-hello-world-example-document-style/[JAX-WS

こんにちは世界の例(document-style)]

統合 リンク://タグ/java/[java] jax-ws webサービス