3、webService CXF的应用1 tomcat的配置方法
来源:互联网 发布:淘宝联盟一直不提现 编辑:程序博客网 时间:2024/06/03 21:56
其实配置CXF方式挺多,这一章节,重点是通过tomcat启动时 加载WebService CXF 的方式。
好,下面 我们通过具体的代码来实现,
我这里用的是maven项目,首先pom.xml 的基础jar的引用
<dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.2.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>4.2.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>4.2.6.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>4.2.6.RELEASE</version> </dependency> <!-- cxf begin --> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>3.1.6</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-transports-http</artifactId> <version>3.1.6</version> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-ws-security</artifactId> <version>3.1.6</version> </dependency> <!-- cxf end --> </dependencies>
配置web.xml文件
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>cxf</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:*spring-cxf-server.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <description>Apache CXF Endpoint</description> <display-name>cxf</display-name> <servlet-name>cxf</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>cxf</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> <session-config> <session-timeout>60</session-timeout> </session-config></web-app>
配置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: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="calculator" address="/calculator" implementor="com.webService.cxf.CalculatorServiceImpl" /></beans>
接口的定义
package com.webService.cxf;import javax.jws.WebService;@WebServicepublic interface CalculatorService {int add(int a, int b); String concat(String a, String b);}
接口的实现
package com.webService.cxf;import javax.jws.WebService;@WebService(endpointInterface="com.webService.cxf.CalculatorService",serviceName="calculator")public class CalculatorServiceImpl implements CalculatorService { public int add(int a, int b) { return a + b; } public String concat(String a, String b) { return a + b; }}
将项目加载到tomcat中 启动 就可以使用了
在浏览器中 输入http://localhost:8080/calculator?wsdl 并出现以下页面时,则表示启动成功
通过代码测试
package com.webService.cxf;import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;/** * Created by kangz on 2016/12/13. */public class Textcxf { public static void main(String[] args) { // TODO Auto-generated method stub //调用WebService JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean(); factory.setServiceClass(CalculatorService.class); factory.setAddress("http://localhost:8080/calculator"); CalculatorService service = (CalculatorService) factory.create(); System.out.println("[result]" + service.add(5,10)); }}
参考文档https://my.oschina.net/u/1407116/blog/262865
0 0
- 3、webService CXF的应用1 tomcat的配置方法
- 4、webService CXF的应用2 Spring的配置方法
- cxf+Spring的webservice应用
- 5、webService CXF的应用3 原始用法
- 力所能及之webservice CXF框架的应用
- cxf+Spring的webservice应用--拦截器
- CXF配置的方式发布WebService并运行于Tomcat容器
- CXF配置的方式发布WebService并运行于Tomcat容器
- WebService中CXF的简单的配置和应用(ssm框架)
- webservice的CXF框架
- 搭建基于CXF的WebService服务器,及其应用
- 搭建基于CXF的WebService服务器,及其应用
- 搭建基于CXF的WebService服务器及其应用
- 应用CXF开发RESTful风格的WebService入门实例
- CXF框架的restful webservice 环境配置(一) 服务端
- CXF框架的restful webservice 环境配置(二) 客户端
- Webservice的cxf开发_使用spring配置客户端
- 基于spring+hibernate+cxf写的webservice服务,详细配置
- S4.6_Struts2_Annotation action动作类使用annotation注解的配置方式
- webview控件介绍
- android启动页广告欢迎界面
- 一汽丰田RAV4电路图2012至2013
- java web各种路径获取
- 3、webService CXF的应用1 tomcat的配置方法
- MAKEFILE基本写法.
- 5分钟完全理解android handler
- CNN for image retrieval
- TCP的窗口滑动机制与拥塞控制
- SVN提交报错:Unable to connect to a repository at URL
- C语言 简单链式哈希
- 第六章 使用C#开发数据库应用系统 上机练习1-4
- 长连接和短连接