CXF整合spring
来源:互联网 发布:mac口红a17是什么颜色 编辑:程序博客网 时间:2024/05/20 18:18
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。
0 0
- 五、CXF整合Spring
- CXF整合Spring
- CXF WebService整合Spring
- Spring 整合 CXF
- CXF整合Spring入门教程
- CXF WebService整合Spring
- CXF WebService整合Spring
- cxf和spring整合
- spring+cxf+bonecp整合
- CXF WebService整合Spring
- CXF Spring整合案例
- CXF WebService整合Spring
- cxf和spring整合
- CXF WebService整合Spring
- CXF WebService整合Spring
- CXF WebService整合Spring
- cxf 与 spring整合
- CXF整合spring
- Cut Ribbon
- 转:C/C++:memmove、memcpy、strcpy三者的区别
- memmove函数的使用方法
- 复制当前目录及其子目录下面的所有的txt文件,如果有文件名相同则重命名为bak01,bak02 ......
- 使用 Apache CXF 实现 Web Service 详解
- CXF整合spring
- Apache Cxf WebService整合Spring(1)
- Apache Cxf WebService整合Spring(2)
- cxf小实例
- Apache CXF 客户端调用 超时设置
- 用js来刷新当夜页面,保留参数
- Linux下python默认版本设置
- arch下ibus选择
- 大数据下Sql优化心得记录