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";
 }

 

附上两个额外的jar包下载地址:

xbean-spring-2.8.jar
http://ftp.cica.es/mirrors/maven2/org/apache/xbean/xbean-spring/2.8/

jaxws-spring-1.8.jar
http://download.java.net/maven/2/org/jvnet/jax-ws-commons/spring/jaxws-spring/1.8/
 
}

 

上面的代码在eclipse中会出现一个xml错误,参考:
http://forums.java.net/jive/thread.jspa?threadID=27946&tstart=45

在applicationContext.xml中的beans节点-xsi:schemaLocation中,把http://.../spring/core.xsd和servlet.xsd中的http改为https:

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
    https://jax-ws.dev.java.net/spring/core.xsd
    http://jax-ws.dev.java.net/spring/servlet
    https://jax-ws.dev.java.net/spring/servlet.xsd"

AOP要用的包:
1) aopalliance-1.0.jar
http://sourceforge.net/projects/aopalliance/files/aopalliance/1.0/aopalliance.zip/download

 

2) aspectjweaver.jar

posted on 2010-12-09 12:08  aurawing  阅读(378)  评论(0编辑  收藏  举报