xfire开发webservice整合springstruts2配置步骤:
《1》、导包
struts2:
1.commons-logging-1.0.4.jar
2.freemarker-2.3.13.jar
3.ognl-2.6.11.jar
4.struts2-core-2.1.6.jar
5.xwork-2.1.2.jar
6.commons-fileupload-1.2.1.jar
7.commons-io-1.3.2.jar
8.struts2-spring-plugin-2.1.6.jar
spring2:
1.log4j-1.2.14.jar
2.aspectjweaver.jar
3.aspectjrt.jar
4.spring.jar
xfire-1.2.6(从网上下载新版本,然后把jar包导入WEB-INF\lib下:xfire-all-1.2.6.jar和lib下的所有包)
《2》、删除一些会冲突的包
把lib下的x-fire中的spring-1.2.6.jar删掉,它会和spring2中的spring.jar包发生冲突。
《3》配置web.xnl
<?xmlversion="1.0"encoding="UTF-8"?>
<web-appxmlns="http://java.sun.com/xml/ns/j2ee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"version="2.4"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext-*.xml,classpath:org/codehaus/xfire/spring/xfire.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>xfireServlet</servlet-name>
<servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>xfireServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<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>/servlet/XFireServlet/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
</web-app>
《4》配置struts.xml(在该例子中还用不到它,以下配置只是与spring2集成)
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEstrutsPUBLIC
"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constantname="struts.objectFactory"value="spring"/>
<packagename="public"extends="struts-default">
<actionname="login"class="loginAction">
......
</action>
</package>
</struts>
《5》配置applicationContext-beans.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<beanid="connectDb"class="jxust.zjh.db.ConnectDb"/>
<beanid="educate"class="jxust.zjh.educateImpl"/>
<beanname="helloService"class="org.codehaus.xfire.spring.ServiceBean">
<propertyname="serviceBean"ref="educate"/>
<propertyname="serviceClass"value="jxust.zjh.Ieducate"/>
<propertyname="inHandlers"ref="addressingHandler"/>
</bean>
<beanid="addressingHandler"class="org.codehaus.xfire.addressing.AddressingInHandler"/>
</beans>
《6》配置applicationContext-actions.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
<beanid="public"abstract="true">
<propertyname="connectDb"ref="connectDb"/>
</bean>
<beanid="loginAction"class="jxust.zjh.actions.LoginAction"scope="prototype"parent="public">
</bean>
</beans>
《7》修改services.xml(由于用的是spring2.0,所以把xmlns="http://xfire.codehaus.org/config/1.0"放在<service>中)
<?xmlversion="1.0"encoding="UTF-8"?>
<beans>
<servicexmlns="http://xfire.codehaus.org/config/1.0">
<name>educate</name>
<serviceClass>jxust.zjh.Ieducate</serviceClass>
<implementationClass>jxust.zjh.educateImpl</implementationClass>
<style>wrapped</style>
<use>literal</use>
<scope>application</scope>
</service></beans>
《8》编写一个简单的接口和实现类(用来测试)
Ieducate.java
packagejxust.zjh;
publicinterfaceIeducate{
publicStringqueryStudent(Strings_card);
}
EducateImpl.java(该实现类依赖了其他类的对象)
packagejxust.zjh;
publicclassEducateImplimplementsIeducate{
publicStringqueryStudent(Strings_card){
return"该学生学号是:"+s_card;
}
}
这样在浏览器中输入:http://localhost:8080/EducateSystem_server/services/educate?wsdl
就可以看到生成的wsdl文件了
xfire开发webservice整合springstruts2整合结束!