最近重新熟悉下webservice知識,以前用的是axis2,現在用另一種方式spring xfire來實作簡單的webservice;
xfire和axis
xfire比axis性能高
axis比xfire響應時間短
一、在eclipse下建立項目工程xfire
二、導入基本的jar包
commons-codec-1.3.jar
commons-httpclient-3.0.jar
commons-logging-1.0.4.jar
jdom-1.0.jar
jsr181-api.jar
spring.jar
wsdl4j-1.6.1.jar
xfire-all-1.2.6.jar
XmlSchema-1.4.7.jar
三、web.xml配置
[html] view plain copy
- <?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>xfire</display-name>
- <!-- 定義裝入的spring配置檔案 -->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>
- classpath:org/codehaus/xfire/spring/xfire.xml
- /WEB-INF/xfire-servlet.xml
- </param-value>
- </context-param>
- <!-- 自動裝配配置資訊 -->
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <!-- 它主要負責處理由 JavaBean Introspector 功能而引起的緩存洩露 -->
- <listener>
- <listener-class>
- org.springframework.web.util.IntrospectorCleanupListener
- </listener-class>
- </listener>
- <!-- 注意因為servlet-name為xfire,固xfire配置檔案名應該是xfire-servlet.xml -->
- <servlet>
- <servlet-name>xfire</servlet-name>
- <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>xfire</servlet-name>
- <url-pattern>*.ws</url-pattern>
- </servlet-mapping>
- <!-- 配合Spring容器中XFire一起工作的Servlet- -->
- <servlet>
- <servlet-name>xfireServlet</servlet-name>
- <servlet-class>
- org.codehaus.xfire.spring.XFireSpringServlet
- </servlet-class>
- </servlet>
- <servlet-mapping>
- <servlet-name>xfireServlet</servlet-name>
- <url-pattern>/services
- public static void main(String[] args) {
- ApplicationContext ac=new ClassPathXmlApplicationContext("client.xml");
- IHello hello=(IHello)ac.getBean("testWebService");
- hello.sayHello("lubing");
- }
- }