例:metro2+spring3

1.lib

antlr-runtime.jar
commons-logging-1.0.4.jar
jaxws-spring-1.8.jar
org.springframework.asm-3.0.0.RELEASE.jar
org.springframework.beans-3.0.0.RELEASE.jar
org.springframework.context-3.0.0.RELEASE.jar
org.springframework.context.support-3.0.0.RELEASE.jar
org.springframework.core-3.0.0.RELEASE.jar
org.springframework.expression-3.0.0.RELEASE.jar
org.springframework.jdbc-3.0.0.RELEASE.jar
org.springframework.jms-3.0.0.RELEASE.jar
org.springframework.transaction-3.0.0.RELEASE.jar
org.springframework.web-3.0.0.RELEASE.jar
org.springframework.web.servlet-3.0.0.RELEASE.jar
webservices-api.jar
webservices-extra-api.jar
webservices-extra.jar
webservices-rt.jar
webservices-tools.jar
xbean-spring-2.8.jar

log4j.jar

 

 

2.代码:

1)WEB-INFO/applicationContext.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:ws="http://jax-ws.dev.java.net/spring/core"
 xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
 xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://jax-ws.dev.java.net/spring/core
    http://jax-ws.dev.java.net/spring/core.xsd
    http://jax-ws.dev.java.net/spring/servlet
    http://jax-ws.dev.java.net/spring/servlet.xsd">

 <wss:binding url="/add.jws" service="#addService" />
 
 <!-- simplest definition only needs the class name -->
 <ws:service id="addService" impl="foo.MyAddService" />

</beans>

 

 

2)WEB-INFO/web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>TestWS</display-name>

  <!-- this is for Spring -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!-- these are for JAX-WS -->
  <servlet>
    <servlet-name>jaxws-servlet</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSSpringServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>jaxws-servlet</servlet-name>
    <url-pattern>/add.jws</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>

 

 

注意:与单独用metro不同,这里用的是WSSpringServlet而不是WSServlet

 

3) foo.MyAddService.java

package foo;
import javax.jws.WebMethod;
import javax.jws.WebService;


@WebService
public class MyAddService {

 @WebMethod
 public String View()
 {
  return "aabbcc";
 }
 
}

你可能感兴趣的:(Spring3)