这些天项目框架升级,必须学习CXF进行发布WebService,那么必不可少的就是和Spring整合
1.首先创建Web工程SpringCXF
2.导入必须的架包(本人尝试了一下需最低配置,至少需要的架包如下,你可以直接把apache-cxf-2.6.1下lib包直接copy到项目lib目录下,一定OK,呵呵)
3.下一步要进行l的配置,来通过servlet进行Spring的过滤,从而能够查到发布的接口
l
[html]viewplaincopyprint?
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="/2001/XMLSchema-instance"
xmlns="java.sun/xml/ns/javaee" xmlns:web="java.sun/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="java.sun/xml/ns/javaee java.sun/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
spring framework
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>l</param-value>
</context-param>
<listener>
<listener-class>org.t.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>f.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
4.在src目录下新建l文件,用来进行Spring映射,并添加与CXF整合配置
[html]viewplaincopyprint?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:context="/schema/context"
xmlns:jaxws="/jaxws"
xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/schema/beans
/schema/beans/spring-beans-3.0.xsd
/schema/context
/schema/context/spring-context-3.0.xsd
/jaxws
/schemas/jaxws.xsd">
<import resource="classpath:META-INF/l" />
<import resource="classpath:META-INF/l" /><import resource="classpath:META-INF/l" />
</beans>
5.编写接口类并添加CXF注解
[java] view plaincopyprint?
package com;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
@WebService
@SOAPBinding(style = Style.RPC) //在JDK1.6以上就不需要了
public interface IComplexUserService {
public String getUserByName(@WebParam(name = "username") String username);
public void setUser(String username);
}
6.编写接口实现类同时加上CXF注解
[java] view plaincopyprint?
package com;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
@WebService(endpointInterface="com. IComplexUserService ")
@SOAPBinding(style = Style.RPC) //在JDK1.6以上就不需要了
public class ComplexUserService implements IComplexUserService{
public String getUserByName(@WebParam(name ="username")String username){
return "Hello:"+username;
}
public void setUser(String username) {
System.out.println(username);
}
}
7.配置Spring映射文件,
[html] view plaincopyprint?
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="/schema/beans"
xmlns:context="/schema/context"
xmlns:jaxws="/jaxws"
xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/schema/beans
/schema/beans/spring-beans-3.0.xsd
/schema/context
/schema/context/spring-context-3.0.xsd
/jaxws
/schemas/jaxws.xsd">
<import resource="classpath:META-INF/l" />
<import resource="classpath:META-INF/l" /><import resource="classpath:META-INF/l" />
<bean id="userServiceBean" class="com.ComplexUserService" />
<jaxws:server id="userService" serviceClass="com.IComplexUserService" address="/userService">
<jaxws:serviceBean>
<ref bean="userServiceBean" />
</jaxws:serviceBean>
</jaxws:server>
</beans>
8.启动服务器进行发布部署,在浏览器中输入localhost:8080/SpringCXF/services/userService?wsdl,显示如下结果
(注:【localhost:8080/项目名称/l配置的访问地址/spring中配置的address地址/这边不写也没啥事情(暂时没弄明白)?wsdl】)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论