JAXWS + Spring 实现webService示例.docx

上传人:b****2 文档编号:2236497 上传时间:2022-10-28 格式:DOCX 页数:8 大小:58.15KB
下载 相关 举报
JAXWS + Spring 实现webService示例.docx_第1页
第1页 / 共8页
JAXWS + Spring 实现webService示例.docx_第2页
第2页 / 共8页
JAXWS + Spring 实现webService示例.docx_第3页
第3页 / 共8页
JAXWS + Spring 实现webService示例.docx_第4页
第4页 / 共8页
JAXWS + Spring 实现webService示例.docx_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

JAXWS + Spring 实现webService示例.docx

《JAXWS + Spring 实现webService示例.docx》由会员分享,可在线阅读,更多相关《JAXWS + Spring 实现webService示例.docx(8页珍藏版)》请在冰豆网上搜索。

JAXWS + Spring 实现webService示例.docx

JAXWS+Spring实现webService示例

JAX-WS+Springintegrationexample

1.ProjectFolder

Seethefinalprojectfolderstructure.

2.ProjectDependencies

UseMaventogetallthelibrarydependencies.ThekeytointegrateSpringwithJAX-WSisviajaxws-spring.jar.

File:

pom.xml

//maven.apache.org/POM/4.0.0"

xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance"

xsi:

schemaLocation="http:

//maven.apache.org/POM/4.0.0

http:

//maven.apache.org/maven-v4_0_0.xsd">

4.0.0

com.mkyong

WebServicesExample

war

1.0-SNAPSHOT

WebServicesExampleMavenWebapp

http:

//maven.apache.org

junit

junit

3.8.1

test

--Springframework-->

org.springframework

spring

2.5.6

--JAX-WS-->

com.sun.xml.ws

jaxws-rt

2.2.3

--Libraryfrom,integrateSpringwithJAX-WS-->

org.jvnet.jax-ws-commons.spring

jaxws-spring

1.8

org.springframework

spring-core

org.springframework

spring-context

com.sun.xml.stream.buffer

streambuffer

org.jvnet.staxex

stax-ex

webservices

org.apache.maven.plugins

maven-compiler-plugin

2.3.1

1.6

1.6

Note

Thejaxws-spring’spom.xmlhasalotofunnecessarydependencies,youmayneedtoexcludeitviatag.

3.JAX-WSHelloWorld

AsimpleJAX-WSexample,anddependencyinject(DI)“HelloWorldBo”viaSpring.

File:

HelloWorldWS.java

packagecom.mkyong.ws;

importjavax.jws.WebMethod;

importjavax.jws.WebService;

importcom.mkyong.bo.HelloWorldBo;

@WebService

publicclassHelloWorldWS{

//DIviaSpring

HelloWorldBohelloWorldBo;

@WebMethod(exclude=true)

publicvoidsetHelloWorldBo(HelloWorldBohelloWorldBo){

this.helloWorldBo=helloWorldBo;

}

@WebMethod(operationName="getHelloWorld")

publicStringgetHelloWorld(){

returnhelloWorldBo.getHelloWorld();

}

}

4.Beans

Here’stheHelloWorldBoclass,withagetHelloWorld()methodtoreturnasimplestring.

File:

HelloWorldBo.java

packagecom.mkyong.bo;

publicinterfaceHelloWorldBo{

StringgetHelloWorld();

}

File:

HelloWorldBoImpl.java

packagecom.mkyong.bo.impl;

importcom.mkyong.bo.HelloWorldBo;

publicclassHelloWorldBoImplimplementsHelloWorldBo{

publicStringgetHelloWorld(){

return"JAX-WS+Spring!

";

}

}

5.SpringBeansConfiguration

SpringbeansconfigurationfiletobindURLpattern“/hello”to“com.mkyong.ws.HelloWorldWS”webserviceclass.

File:

applicationContext.xml

xmlversion="1.0"encoding="UTF-8"?

>

//www.springframework.org/schema/beans"

xmlns:

xsi="http:

//www.w3.org/2001/XMLSchema-instance"

xmlns:

ws="http:

//jax-

xmlns:

wss="http:

//jax-

xsi:

schemaLocation="http:

//www.springframework.org/schema/beans

http:

//www.springframework.org/schema/beans/spring-beans-2.5.xsd

http:

//jax-

http:

//jax-

http:

//jax-

http:

//jax-

>

bindingurl="/hello">

service>

servicebean="#helloWs"/>

service>

binding>

--Webservicemethods-->

Note

Withthisjaxws-springintegrationmechanism,thesun-jaxws.xmlfileisnolongerrequired.

6.web.xml

Inweb.xml,declares“com.sun.xml.ws.transport.http.servlet.WSSpringServlet“,andlinkitto“/hello“.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1