//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
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“.