Java通过Cxf创建webService接口.docx

上传人:b****6 文档编号:2992233 上传时间:2022-11-16 格式:DOCX 页数:18 大小:48.80KB
下载 相关 举报
Java通过Cxf创建webService接口.docx_第1页
第1页 / 共18页
Java通过Cxf创建webService接口.docx_第2页
第2页 / 共18页
Java通过Cxf创建webService接口.docx_第3页
第3页 / 共18页
Java通过Cxf创建webService接口.docx_第4页
第4页 / 共18页
Java通过Cxf创建webService接口.docx_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

Java通过Cxf创建webService接口.docx

《Java通过Cxf创建webService接口.docx》由会员分享,可在线阅读,更多相关《Java通过Cxf创建webService接口.docx(18页珍藏版)》请在冰豆网上搜索。

Java通过Cxf创建webService接口.docx

Java通过Cxf创建webService接口

Java通过Cxf创建webService接口

一、导入cxf需要的jar包

二、编写服务类

publicclassCxfServiceimplementsCxfServiceImpl{

/*(non-Javadoc)

*@see.liveuc.cxf.service.CxfServiceImpl#getSay(java.lang.String)

*/

@WebMethod

publicStringgetSay(Stringname){

return"say:

"+name+"时间:

"+newDate();

}

}

@WebService

publicclassCxfServiceimplementsCxfServiceImpl{

/*(non-Javadoc)

*@see.liveuc.cxf.service.CxfServiceImpl#getSay(java.lang.String)

*/

@WebMethod

publicStringgetSay(Stringname){

return"say:

"+name+"时间:

"+newDate();

}

}

三、抽取接口

publicinterfaceCxfServiceImpl{

@WebMethod

publicabstractStringgetSay(Stringname);

}

@WebService

publicinterfaceCxfServiceImpl{

@WebMethod

publicabstractStringgetSay(Stringname);

}

四、写启动类

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"?

>

//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/jaxwshttp:

//cxf.apache.org/schemas/jaxws.xsd">

rgb(255,255,255)">

#ff0000">

--

***注意***

手动添加的内容:

xmlns:

jaxws="http:

//cxf.apache.org/jaxws"

http:

//cxf.apache.org/jaxwshttp:

//cxf.apache.org/schemas/jaxws.xsd"

-->

--引入CXFBean定义如下-->

META-INF/cxf/cxf.xml"/>

META-INF/cxf/cxf-extension-soap.xml"/>

META-INF/cxf/cxf-servlet.xml"/>

xmlversion="1.0"encoding="UTF-8"?

>

//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/jaxwshttp:

//cxf.apache.org/schemas/jaxws.xsd">

--***注意***

手动添加的内容:

xmlns:

jaxws="http:

//cxf.apache.org/jaxws"

http:

//cxf.apache.org/jaxwshttp:

//cxf.apache.org/schemas/jaxws.xsd"

-->

--引入CXFBean定义如下-->

META-INF/cxf/cxf.xml"/>

META-INF/cxf/cxf-extension-soap.xml"/>

META-INF/cxf/cxf-servlet.xml"/>

三、在web.xml中配置Spring的加载文件和cxf拦截器

--加载Spring配置文件-->

contextConfigLocation

classpath:

applicationContext.xml

org.springframework.web.context.ContextLoaderListener

--配置CXF配置文件-->

cxf

org.apache.cxf.transport.servlet.CXFServlet

1

cxf

/ws/*

--所有的webservice发布在ws目录下-->

--加载Spring配置文件-->

contextConfigLocation

classpath:

applicationContext.xml

org.springframework.web.context.ContextLoaderListener

--配置CXF配置文件-->

cxf

org.apache.cxf.transport.servlet.CXFServlet

1

cxf

/ws/*

--所有的webservice发布在ws目录下-->

四、编写要提供的webservice接口和实现类

2.编写服务接口

@WebService

publicinterfaceCxfServiceImpl{

@WebMethod

publicabstractStringgetSay(Stringname);

}

3.编写服务具体类

@WebService

publicclassCxfServiceimplementsCxfServiceImpl{

/*(non-Javadoc)

*@see.liveuc.cxf.service.CxfServiceImpl#getSay(java.lang.String)

*/

@WebMethod

publicStringgetSay(Stringname){

return"say:

"+name+"时间:

"+newDate();

}

}

2.编写服务接口

@WebService

publicinterfaceCxfServiceImpl{

@WebMethod

publicabstractStringgetSay(Stringname);

}

3.编写服务具体类

@WebService

publicclassCxfServiceimplementsCxfServiceImpl{

/*(non-Javadoc)

*@seecn.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 幼儿教育 > 幼儿读物

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1