使用Apache CXF和Spring集成创建Web Service
来源:互联网 发布:python简单程序实例 编辑:程序博客网 时间:2024/06/05 18:53
1.创建HelloWorld 接口类
1
package
com.googlecode.garbagecan.cxfstudy.helloworld;
2
import
javax.jws.WebParam;
3
import
javax.jws.WebResult;
4
import
javax.jws.WebService;
5
@WebService
6
public
interface
HelloWorld {
7
public
@WebResult
(name=
"String"
)String sayHi(
@WebParam
(name=
"text"
) String text);
8
}
2.创建HelloWorld实现类
1
package
com.googlecode.garbagecan.cxfstudy.helloworld;
2
public
class
HelloWorldImpl
implements
HelloWorld {
3
public
String sayHi(String name) {
4
String msg =
"Hello "
+ name +
"!"
;
5
System.out.println(
"Server: "
+ msg);
6
return
msg;
7
}
8
}
3.修改web.xml文件
01
<!DOCTYPE web-app PUBLIC
02
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
03
"http://java.sun.com/dtd/web-app_2_3.dtd" >
04
<
web-app
>
05
<
display-name
>cxfstudy</
display-name
>
06
<
servlet
>
07
<
servlet-name
>cxf</
servlet-name
>
08
<
servlet-class
>org.apache.cxf.transport.servlet.CXFServlet</
servlet-class
>
09
<
load-on-startup
>1</
load-on-startup
>
10
</
servlet
>
11
<
servlet-mapping
>
12
<
servlet-name
>cxf</
servlet-name
>
13
<
url-pattern
>/ws/*</
url-pattern
>
14
</
servlet-mapping
>
15
<
listener
>
16
<
listener-class
>org.springframework.web.context.ContextLoaderListener</
listener-class
>
17
</
listener
>
18
19
<
context-param
>
20
<
param-name
>contextConfigLocation</
param-name
>
21
<
param-value
>classpath*:**/spring.xml</
param-value
>
22
</
context-param
>
23
24
</
web-app
>
4.创建spring配置文件并放在classpath路径下
01
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
02
<
beans
xmlns
=
"http://www.springframework.org/schema/beans"
03
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws
=
"http://cxf.apache.org/jaxws"
04
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
05
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
06
<
import
resource
=
"classpath:META-INF/cxf/cxf.xml"
/>
07
<
import
resource
=
"classpath:META-INF/cxf/cxf-extension-soap.xml"
/>
08
<
import
resource
=
"classpath:META-INF/cxf/cxf-servlet.xml"
/>
09
<
jaxws:endpoint
id
=
"helloworld"
implementor
=
"com.googlecode.garbagecan.cxfstudy.helloworld.HelloWorldImpl"
address
=
"/HelloWorld"
/>
10
11
<!-- For client test -->
12
<
jaxws:client
id
=
"helloworldClient"
address
=
"http://localhost:9000/ws/HelloWorld"
serviceClass
=
"com.googlecode.garbagecan.cxfstudy.helloworld.HelloWorld"
/>
13
</
beans
>
5.创建测试类
01
package
com.googlecode.garbagecan.cxfstudy.helloworld;
02
import
org.springframework.context.ApplicationContext;
03
import
org.springframework.context.support.ClassPathXmlApplicationContext;
04
public
class
SpringClient {
05
public
static
void
main(String[] args) {
06
ApplicationContext context =
new
ClassPathXmlApplicationContext(
"spring.xml"
);
07
HelloWorld helloworld = (HelloWorld)context.getBean(
"helloworldClient"
);
08
System.out.println(helloworld.sayHi(
"kongxx"
));
09
}
10
}
6.测试
6. 1.首先启动tomcat或者使用maven的jetty,并访问http://localhost:9000/ws/HelloWorld?wsdl来验证web service已经启动并且生效;
6. 2.然后运行测试类来验证web service。
- 使用Apache CXF和Spring集成创建Web Service
- 使用Apache CXF和Spring集成创建Web Service
- 使用Apache CXF和Spring集成创建Web Service
- 使用Apache CXF创建Web Service
- 使用Apache CXF创建简单Web Service
- cxf+web service(四)cxf+spring集成
- 使用CXF和Spring搭建Web Service
- 使用CXF创建WEB SERVICE
- 使用apache CXF和maven开发Web Service
- 使用apache CXF和maven开发Web Service
- 使用apache CXF和maven开发Web Service
- 使用apache CXF和maven开发Web Service
- 使用apache CXF和maven开发Web Service
- 使用apache CXF和maven开发Web Service
- 使用apache CXF和maven开发Web Service
- [转]使用 Spring 和 Apache CXF 设计和实现 POJO Web 服务,第 1 部分: 使用 CXF 和 Spring 创建 Web 服务
- 使用 Apache CXF 实现 Web Service 详解
- 使用Apache CXF实现Web Service
- 1的个数
- CSS Sprite的应用
- JSON Support in Qt
- Linux下的硬件驱动——USB设备(下)
- onItemClick监听器四个arg参数
- 使用Apache CXF和Spring集成创建Web Service
- hdu 2005
- 修改Apache配置文件开启gzip压缩传输
- linux内存管理---物理地址、线性地址、虚拟地址、逻辑地址之间的转换
- 散列表(四):冲突处理的方法之开地址法(二次探测再散列的实现)
- 泛函分析前导课程
- Uva 10859 - Placing Lampposts 树形DP+保持一个值最优的情况下维护另一个最优值
- 从零开始最短路径学习Hadoop之06----构建Hadoop集群
- Android模仿文件夹管理实例