CXF
与
spring
集成
1
.
新建
web
project ,
并加入
a
pache-cxf-2.0.7/lib
所有包
,编写要发布的
web service
接口和实现
.
这一步,与前面一样。
import javax.jws.WebService;
@WebService
public interface HelloWorld {
public String sayHello(String text);
}
import javax.jws.WebService;
@WebService(endpointInterface="test.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
public String sayHello(String text) {
return "Hello" + text ;
}
}
@WebService
注解表示是要发布的
web
服务
2.
在
spring-cxf.xml
配置发布的
web service
<?
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-extension-soap.xml"
/>
<
import
resource
=
"classpath:META-INF/cxf/cxf-servlet.xml"
/>
<
bean
id
=
"hello"
class
=
"test.HelloWorldImpl"
/>
<
jaxws:endpoint
id
=
"helloWorld"
implementor
=
"#hello"
address
=
"/HelloWorld"
/>
</
beans
>
注意:
<
jaxws:endpoint
id
=
"helloWorld"
implementor
=
"#hello"
address
=
"/HelloWorld"
/>
id
:指在
spring
配置的
bean
的
ID.
Implementor:
指明具体的实现类
.
Address:
指明这个
web service
的相对地址,
3.
配置
web.xml
文件:
<?
xml
version
=
"1.0"
encoding
=
"UTF-8"
?>
<
web-app
version
=
"2.4"
xmlns
=
"http://java.sun.com/xml/ns/j2ee"
xmlns:xsi
=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
=
"http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
>
<
context-param
>
<
param-name
>
contextConfigLocation
</
param-name
>
<
param-value
>
classpath:spring-cxf.xml
</
param-value
>
</
context-param
>
<
listener
>
<
listener-class
>
org.springframework.web.context.ContextLoaderListener
</
listener-class
>
</
listener
>
<
servlet
>
<
servlet-name
>
CXFServlet
</
servlet-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
>
/ws/*
</
url-pattern
>
</
servlet-mapping
>
</
web-app
>
4
.
部署到
tomcat
服务器
,
输入
:http://localhost:8080/<web-app-name>/
HelloWorld?wsdl,
将显示这个
web service
的
wsdl.
注意:如果web.xml
配置
<
servlet-name
>
CXFServlet
</
servlet-name
>
<
url-pattern
>
/ws/*
</
url-pattern
>
则访问地址为:
http://localhost:8080/<web-app-name>/ws/
HelloWorld?wsdl
5.
下面就开始创建一个客户端程序,访问这个web service,
同样新建
java project ,
并加入
a
pache-cxf-2.0.7/lib
所有包
.
创建与具体webservice
技术无关的业务接口HelloWorld.java
public interface HelloWorld {
public String sayHello(String text);
}
6.
配置
spring-client.xml
<
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-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd"
>
<
bean
id
=
"client"
class
=
"test.HelloWorld"
factory-bean
=
"clientFactory"
factory-method
=
"create"
/>
<
bean
id
=
"clientFactory"
class
=
"org.apache.cxf.jaxws.JaxWsProxyFactoryBean"
>
<
property
name
=
"serviceClass"
value
=
"test.HelloWorld"
/>
<
property
name
=
"address"
value
=
"http://localhost:9000/helloWorld"
/>
<!--
这个地方的地址一定要注意,正确的
-->
</
bean
>
</
beans
>
7
.测试:
import
org.springframework.context.ApplicationContext;
import
org.springframework.context.support.ClassPathXmlApplicationContext;
import
test.HelloWorld;
public
class
Test {
public
static
void
main(String[] args) {
ApplicationContext ctx =
new
ClassPathXmlApplicationContext(
"spring-client.xml"
);
HelloWorld client = (HelloWorld) ctx.getBean(
"client"
);
String result = client.sayHello(
"
你好
!"
);
System.
out
.println(result);
}
}
分享到:
相关推荐
本java工程实现了spring+cxf快速开发webservice jar包齐全导入myeclipse可直接二次开发
通过实例讲解运用spring和CXF开发webservice,通过调用webservice中的方法向数据库中插入数据
开发环境jdk1.7,cxf版本3.1.17。 spring整合CXF开发webService所需jar包。
Spring+CXF 发布WebService服务
Spring+CXF开发WebService源代码,包括所需要的基本jar,调试通过,适合初学者入门学习。
第一天: 什么是webservice? 从案例(便民查询网站)分析如何实现?...CXF开发webservice: CXF入门程序 Spring+cxf整合(重点) CXF发布rest的webservice。(重点) 综合案例: 实现便民查询网站
使用 CXF 做 webservice 简单例子 Apache CXF 是一个开放源代码框架,提供了用于方便地构建和开发 Web 服务的可靠基础架构。它允许创建高性能和可扩展的服务,您可以将这样的服务部署在 Tomcat 和基于 Spring 的轻...
CXF2+Spring2.5开发WebService实例,需要导入jar包
基于Spring和CXF开发webservice的开发模板框架,spring和cxf都已经配置好,只需要直接写webservice类就行了。具体的配置细节参照本人博客。
https使用jks,附件里有证书文件,需要自己修改路径
cxf开发webservice与spring整合所需jar包
Spring + cxf = webservice 完整实例源码免费下载 完全免费。此资源仅为文档提供。 版权为百度文档 "Spring + cxf = webservice 完整实例源码免费下载" 所有。
Web项目中基于Maven与Spring整合的WebService之cxf的实现⬇️ 详情请参考如下链接: https://locqi.github.io/locqi.com/2018/09/05/Eclipse+Maven+Spring+CXF-create-WebService/
mybatis+spring+cxf webservice服务 项目框架代码例子,绝对是可以参考的,信不信,只有下载之后才知道
基于spring注解的cxf实现webservice
这是讲解cxf的权威开发文档 文档内容:Apache CXF 提供方便的Spring整合方法,可以通过注解、Spring标签式配置来暴露Web Services和消费Web Services
Apache CXF 提供方便的Spring整合方法,可以通过注解、Spring标签式配置来暴露Web Services和消费Web Services 各种类型的Annotation。@WebService和@WebMethod是WSDL映射Annatotion。这些Annotation将描述Web ...
Spring+CXF+tomcat开发webservice,包含服务端和客户端,导入myeclipse就可以用。帮助大家搭建webservice框架,实现webservice功能。
花费了1天整理的jar包,spring的版本较低,但是可以用。
NULL 博文链接:https://chilongxph.iteye.com/blog/510707