CXF是webService的框架,能够和spring无缝整合
##服务端编写
1.创建动态web项目
2.导入cxf和spring相关jar包(CXF核心包:cxf-2.4.2.jar)
3.在web.xml中配置CXF框架的核心Servlet
?
|
1
2
3
4
5
6
7
8
9
10
11
12
|
<servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<init-param>
<param-name>config-location</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/webservice/*</url-pattern>
</servlet-mapping>
|
4.提供spring框架的配置文件applicationContext.xml
applicationContext.xml的约束:
?
|
1
2
3
4
5
6
7
8
9
10
|
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/bindings/soap
http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
|
5.开发一个服务类
注:服务类必须加注解 @WebService
6.在spring中配置文件中注册服务
?
|
1
2
|
<jaxws:endpoint id="" address="/hello" implementor=""></jaxws:endpoint>
<!-- id为服务的id,任意填写 address 为访问地址 implementor为服务类的全类名-->
|
启动web工程,浏览器访问
###客户端
(用wsdl2java命令生成本地代码调用)
1,在wsdl2java.bat命令所在的文件夹下打开命令窗口,输入:wsdl2java -d . 路径
(路径为service发布后页面的wsdl的全路径,service访问的路径名加?wsdl),回车后会在当前文件夹下生成文件夹
2.把文件夹复制到项目中
(用spring文件注册代理对象调用)
1.创建项目,可以不是web项目,导入jar包
2.将生成的接口复制到项目中。
3.创建applicationContext.xml文件中配置代理对象
?
|
1
2
|
<jaxws:client id="" address = "" serviceClass =""></jaxws:client>
<!-- id值随意, adress的值为wsdl的路径值,当不在本机是,须要修改ip serviceClass为接口的全路径-->
|
4.编写实现类(如下为例子)
?
|
1
2
3
4
5
6
7
|
public static void main(String[] args) {
//创建工厂对象
ClassPathXmlApplicationContext cts = new ClassPathXmlApplicationContext("applicationContext.xml");
Fun1 proxy = (Fun1) cts.getBean("myclient");
String string = proxy.sayHello("呵呵", 12);
System.out.println(string);
}
|
相关文章
猜你喜欢
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-27 81
-
2025-05-25 55
-
Spring boot通过HttpSessionListener监听器统计在线人数的实现代码
2025-05-29 35 -
2025-05-25 64
-
2025-05-29 39
热门评论

