开发工具:eclipse3.5
数据库:mysql5
框架:
- spring2.5.5
- cxf2.2.6
整合步骤:
cxf与spring的整合十分方便.cxf的lib中就内置了spring的支持.cxf2.2.6中包含的spring包为2.5.6版本.但是想用自己的spring也可以,在导入cxf包的时候不导入spring的包就可以了.
spring,直接导入spring.jar 就可以了,方便起见.
到这一步就可以开始测试是否整合成功.
spring的配置文件.
<?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:simple="http://cxf.apache.org/simple"
xmlns:lang="http://www.springframework.org/schema/lang"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.0.xsd
http://cxf.apache.org/simple http://cxf.apache.org/schemas/simple.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
</beans>
web.xml配置文件:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>
/service/*</url-pattern>
</servlet-mapping>
*红色部分的路径会影响生成webservice的路径
写测试类:
@WebService
public interface ILoginService {
public interface ILoginService {
@WebMethod
public int login(@WebParam(name = "username") String username,
@WebParam(name = "passwords") String password);
public int login(@WebParam(name = "username") String username,
@WebParam(name = "passwords") String password);
}
发布: 在spring中发布webservice
<bean id="loginService" class="com.wks.webservice.impl.LoginService"></bean>
<jaxws:endpoint implementor="#loginService" address="/login">
</jaxws:endpoint>
<jaxws:endpoint implementor="#loginService" address="/login">
</jaxws:endpoint>
最后就可以根据地址测试了. 发布成功.
Spring 和 cxf的整合就完成了.