Spring+CXF的WebServices简单示例
2024-10-14 02:32:55
本文就最简单的WebServices示例来演示Spring和CXF的整合。
- 使用Maven创建webapp项目,pom如下
<properties>
<cxf.version>2.2.3</cxf.version>
</properties> <dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.4.RELEASE</version>
</dependency> <dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- Jetty is needed if you're are not using the CXFServlet -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency> <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies> - 需要暴露的服务
@WebService
public class Hello {
public String say(){
return "hello,kevin";
}
} - 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"> <bean id="hello" class="net.oseye.Hello"></bean> <import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> <jaxws:endpoint id="helloService" implementor="#hello" address="/hello" />
</beans> - web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app>
<display-name>Archetype Created Web Application</display-name> <!-- needed for ContextLoaderListener -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param> <!-- Bootstraps the root web application context before servlet initialization -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <servlet>
<servlet-name>cxf</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>cxf</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app> - 运行
最新文章
- Win8 安装 Scrapy
- 查询Oracle锁表和解决方法
- elk收集分析nginx access日志
- HTML解析组件HtmlAgilityPack使用
- Solr 5.x集成中文分词word,mmseg4j
- OpenGL中投影矩阵的推导
- 加入商品分类信息,考虑用户所处阶段的 图模型 推荐算法 Rws(random walk with stage)
- 非原生APP开发中可以用到的JQ插件
- Lake Counting (DFS)
- 2017-12-30-如何彻底清除现存GIT仓库的大量提交历史
- NTP 时间同步协议
- 【Tomcat】CentOS7.0下安装多个Tomcat及其配置
- css美化页面
- ubuntu 禁用自带的nouveau显卡驱动,安装NVIDIA显卡驱动
- mono修改配置
- topcoder srm 684 div1
- Markdown基础教程
- linux-shell脚本高并发对文本url批量下载
- (2)集合 遍历set集合
- 20155231 2016-2017-2 《Java程序设计》第1周学习总结