使用CXF和spring发布rest服务
来源:互联网 发布:淘宝上好评后怎么截图 编辑:程序博客网 时间:2024/05/29 10:54
创建web工程:
web.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app> <!-- 配置Spring的配置文件 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>WEB-INF/bean.xml</param-value> </context-param> <!-- 配置Spring的web Context监听器,将Spring与web工程集成在一起 --> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <!-- 配置CXF --> <servlet> <servlet-name>CXFServlet</servlet-name> <display-name>CXF Servlet</display-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> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
发布的服务在localhost:8080/test/service/ 可以看到
bean.xml:
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:task="http://www.springframework.org/schema/task" xmlns:util="http://www.springframework.org/schema/util" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:jaxrs="http://cxf.apache.org/jaxrs" 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://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd"> <!-- 将Bean托管给Spring --> <bean id="hello" class="test.HelloImpl"> </bean> <!-- 配置需要暴露的BeanService --> <jaxrs:server id="restContainer2" address="/resthello"> <jaxrs:serviceBeans> <ref bean="hello" /> </jaxrs:serviceBeans> </jaxrs:server> </beans>
Hello.java:
package test;import javax.jws.WebMethod;import javax.jws.WebService;import javax.ws.rs.GET;import javax.ws.rs.Path;import javax.ws.rs.QueryParam;@Path("/hello")@WebServicepublic interface Hello { @WebMethod(operationName = "output", action = "urn:Output") @GET @Path("/getName") String output(); }
HelloImpl.java:
package test;import java.util.Date;import javax.jws.WebService;public class HelloImpl implements Hello{ @Override public String output() { // TODO Auto-generated method stub System.out.println("output"); return "hello world"; }}
结合bean.xml中设置的address=”/resthello”,在Hello.java中设置的path可以通过路径:http://localhost:8080/test/service/resthello/hello/getName访问
0 0
- 使用CXF和spring发布rest服务
- 使用cxf发布rest服务接口,和spring的整合
- 使用CXF和Spring发布Soap服务
- 使用Spring与CXF编写rest服务
- webservice--CXF+Spring整合发布REST的服务
- WebService之CXF整合Spring框架发布REST服务
- 使用Spring + CXF 发布WebService服务
- CXF系列之JAX-RS:CXF与spring集成发布REST服务
- apache-cxf-3.0.4和spring实现rest服务
- 使用 CXF 开发 REST 服务
- 使用cxf开发REST服务
- 使用 CXF 开发 REST 服务
- 使用 CXF 开发 REST 服务
- webservice--CXF发布REST的服务
- CXF+Spring 发布SOAP服务
- cxf+spring发布RESTful服务
- 8、CXF与Spring整合发布http rest 风格的WebService服务
- spring boot整合cxf发布webservice服务和spring boot整合cxf客户端调用webservice服务
- Cookie介绍及JavaScript操作Cookie方法详解
- 教学反馈系统-阶段项目1
- leetcode 1 Two Sum
- VB和C#中serialPort控件导入DataReceived事件
- trie树(简单版本)
- 使用CXF和spring发布rest服务
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
- 一起talk GCC吧(第四回:GCC警告)
- Android使用腾讯定位SDK显示当前地址
- LeetCode 208: Implement Trie (Prefix Tree)
- 第十六周 程序阅读
- 打车软件烧钱背后的商业逻辑
- android 自定义对话框 位置
- 面试——数据结构