Java通过Cxf创建webService接口Word下载.docx
- 文档编号:15903221
- 上传时间:2022-11-16
- 格式:DOCX
- 页数:18
- 大小:48.80KB
Java通过Cxf创建webService接口Word下载.docx
《Java通过Cxf创建webService接口Word下载.docx》由会员分享,可在线阅读,更多相关《Java通过Cxf创建webService接口Word下载.docx(18页珍藏版)》请在冰豆网上搜索。
+newDate();
}
}
@WebService
publicclassCxfServiceimplementsCxfServiceImpl{
/*(non-Javadoc)
*@see.liveuc.cxf.service.CxfServiceImpl#getSay(java.lang.String)
*/
@WebMethod
publicStringgetSay(Stringname){
}
}
三、抽取接口
publicinterfaceCxfServiceImpl{
publicabstractStringgetSay(Stringname);
publicinterfaceCxfServiceImpl{
@WebMethod
四、写启动类
publicclassStartService{
publicStartService(){
//实例化服务类
CxfServicecs=newCxfService();
//用ServerFactoryBean发布服务
JaxWsServerFactoryBeansf=newJaxWsServerFactoryBean();
//设置服务访问地址
sf.setAddress("
http:
//127.0.0.1:
9090/say"
);
//设置服务接口类
sf.setServiceClass(CxfServiceImpl.class);
//设置服务具体类
sf.setServiceBean(cs);
//开启服务
sf.create();
publicstaticvoidmain(String[]args){
newStartService();
二、cxf与Spring集成webservice
二、编写Spring配置文件applicationContext.xml
?
<
xmlversion="
1.0"
encoding="
UTF-8"
>
beansxmlns="
//www.springframework.org/schema/beans"
xmlns:
xsi="
//www.w3.org/2001/XMLSchema-instance"
jaxws="
//cxf.apache.org/jaxws"
xsi:
schemaLocation="
//www.springframework.org/schema/beans
http:
//www.springframework.org/schema/beans/spring-beans.xsd
//cxf.apache.org/jaxwshttp:
//cxf.apache.org/schemas/jaxws.xsd"
<
SPANstyle="
BACKGROUND-COLOR:
rgb(255,255,255)"
COLOR:
#ff0000"
SPAN>
!
--
***注意***
手动添加的内容:
-->
/SPAN>
--引入CXFBean定义如下-->
importresource="
classpath:
META-INF/cxf/cxf.xml"
/>
META-INF/cxf/cxf-extension-soap.xml"
/>
META-INF/cxf/cxf-servlet.xml"
/beans>
//www.springframework.org/schema/beans
//www.springframework.org/schema/beans/spring-beans.xsd
--***注意***
三、在web.xml中配置Spring的加载文件和cxf拦截器
--加载Spring配置文件-->
context-param>
param-name>
contextConfigLocation<
/param-name>
param-value>
applicationContext.xml<
/param-value>
/context-param>
listener>
listener-class>
org.springframework.web.context.ContextLoaderListener<
/listener-class>
/listener>
--配置CXF配置文件-->
servlet>
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>
url-pattern>
/ws/*<
/url-pattern>
--所有的webservice发布在ws目录下-->
/servlet-mapping>
四、编写要提供的webservice接口和实现类
2.编写服务接口
@WebService
3.编写服务具体类
2.编写服务接口
3.编写服务具体类
*@seecn.
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 通过 Cxf 创建 webService 接口