cxf和spring开发web service--服务器端
来源:互联网 发布:全球潮汐软件下载 编辑:程序博客网 时间:2024/06/05 22:59
服务器端
1. 编写服务
首先编写服务接口,例子很简单,任何调用这个接口,会返回“Hello" + 输入内容
package demo.spring.service;
import javax.jws.WebService;
/**
File: HelloWorld.java
Description: TODO
@author
@date 2016年11月2日 下午1:39:46
@version 1.0
**/
@WebService
public interface HelloWorld {
String sayHi(String text);
}
编写实现类:
package demo.spring.service;
import javax.jws.WebService;
/**
File: HelloWorldImpl.java
Description: TODO
@author
@date 2016年11月2日 下午1:40:58
@version 1.0
**/
@WebService(endpointInterface="demo.spring.service.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
@Override
public String sayHi(String text) {
System.out.println("Server sayHi called");
return "Hello " + text;
}
}
@Webservice注解,告诉cxf在创建wsdl时应该使用哪个接口
2. 编写spring bean
再web-inf目录下新建beans.xml
<?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:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="helloWorld" implementor="demo.spring.service.HelloWorldImpl" address="/HelloWorld"/>
</beans>
jaxws endpoint的bean由3部分组成
id 在spring context中bean的id
implementor 指定负责执行的class名(犬类名)
address 指定服务提供的路径,相对路径,例如上面address=/helloworld,则真正wsdl的路径为: http://localhost:8080/projectname/helloworld?wsdl
3. 配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.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>/*</url-pattern>
</servlet-mapping>
</web-app>
配置完成后,部署运行
http://localhost:8080/springwebservice/
wsdl路径为: http://localhost:8080/springwebservice/HelloWorld?wsdl
客户端
1. 获取wsdl的路径 http://localhost:8080/springwebservice/HelloWorld?wsdl
进入src目录,运行指令生成客户端代码:
wsimport -keep http://localhost:8080/springwebservice/HelloWorld?wsdl
然后编写测试代码:
HelloWorldImplService factory = new HelloWorldImplService();
HelloWorld helloWorld = factory.getHelloWorldImplPort();
String value = helloWorld.sayHi("某某某");
System.out.println(value);
运行测试代码
客户端和服务器端均有相关打印信息,则测试完成
- cxf和spring开发web service--服务器端
- 用cxf+spring开发web service
- Spring boot 整合CXF开发web service
- Spring boot 整合CXF开发web service
- Web Service ---- CXF + SPRING 开发 SOAP服务
- Spring boot 整合CXF开发web service
- Spring boot 整合CXF开发web service
- 使用CXF开发web service 的服务器端(三)
- 使用CXF和Spring搭建Web Service
- CXF简单实现web service服务器端
- cxf+web service(四)cxf+spring集成
- Eclipse安装CXF插件开发java web service 集成Spring
- Eclipse安装CXF插件开发java web service 集成Spring
- Eclipse安装CXF插件开发java web service 集成Spring
- Eclipse安装CXF插件开发java web service 集成Spring
- Eclipse安装CXF插件开发java web service 集成Spring
- 用cxf做基于spring的web service开发(八)
- 使用Apache CXF和Spring集成创建Web Service
- Android关于OnTouch 和OnClick同时调用冲突的解决方案
- Thymeleaf 之 内置对象、定义变量、URL参数及标签自定义属性
- iOS 记住网页(UIWebView)上次浏览的位置
- 自定义网桥
- Warning:Gradle version 2.10 is required. Current version is 2.4. If using the gradle wrapper, try ed
- cxf和spring开发web service--服务器端
- 《大话数据结构》
- 百度云网盘下载无反应javascript:void(0)救急办法
- Swift 3.0 label富文本
- ubuntu删除文件的命令
- dubbo中的多播multicast://224.5.6.7:1234
- expdp使用parfile配置文件做数据导出
- 《大话数据结》
- web项目中引入log4j——日志(方便检查问题)