直接上代码吧:
一:先把cxf的jar包导进去,我是直接在官网下载的cxf的包,解压后直接把lib文件夹里的jar一次
性全部丢进去了,因为在学习,还不知道哪些包要哪些包不要的,所以干脆直接放进去
二:写一个简单的接口
package test.wervice;
import javax.jws.WebService;
@WebService
public interface HelloWorld {
void sayHi(String name);
}
三:写一个接口实现类
package test.wervice.impl;
import javax.jws.WebService;
import test.wervice.HelloWorld;
@WebService(endpointInterface="test.wervice.HelloWorld")
public class HelloWorldImpl implements HelloWorld{
public void sayHi(String name) {
System.out.println("helloWorld"+name);
}
}
四:配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- 配置application的加载 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/applicationContext.xml</param-value>
</context-param>
<!-- spring的监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 配置cxf的servlet -->
<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>/cxf/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
五:在WEB-INF下面创建applicationContext.xml,配置如下
<?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:p="http://www.springframework.org/schema/p"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:cxf="http://cxf.apache.org/core"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<!-- 实现接口的bean -->
<bean id="hello" class="test.wervice.impl.HelloWorldImpl"/>
<!--第一种配置-->
<jaxws:endpoint address="/HelloWorld" >
<jaxws:implementor ref="hello" />
</jaxws:endpoint>
<!-- 第二种配置方法 -->
<!-- <jaxws:endpoint address="/HelloWorld" implementor="test.wervice.impl.HelloWorldImpl"/> -->
</beans>
最后启动项目,在浏览器端输入address的地址:http://localhost:8082/testWebservice/cxf/HelloWorld?wsdl
得到如下结果:
- 大小: 148.8 KB
分享到:
相关推荐
WebService的CXF整合Spring有源码和jar包
cxf与spring整合webservice所需jar
webservice与spring整合学习文档,里面的项目部署上就可以使用
WebService小白学习 之 Spring整合CXF,添加拦截器。 博客学习地址:https://blog.csdn.net/qq_37902949/article/details/81262826
webserivce.、cxf整合spring,用的是spring3和cxf3。欢迎大家下载尝试
13.为CXF与Spring整合发布WebService添加拦截器进行权限控制
cxf与spring整合,以及webservice传输验证demo
Web Service学习-CXF与Spring整合为JavaEE应用发布WebService(三)
这个是cxf+spring发布webservice和restservice的服务端项目
cxf开发webservice与spring整合所需jar包
12.CXF与Spring整合为JavaEE应用发布WebService
CXF WebService整合Spring示例工程代码demo可以直接导入eclipse。参照网页http://www.cnblogs.com/hoojo/archive/2011/03/30/1999563.html 完成的webService服务提供。 大致步骤: 1.引入cxf和其他需要的jar包,(本...
webservice cxf spring整合返回list,bean,string,json,xml项目完整实例
CXF WebService整合Spring 原项目,可运行
webservice cxf 整合spring例子源代码.相关博客的介绍: http://blog.csdn.net/dream_broken/article/details/35331949
完整可用的spring整合CXF示例项目,包括服务发布端和调用端两个项目,包括CXF拦截器的实现的简单的授权校验
14.CXF与Spring整合的第二种方式_让JavaEE应用依赖第三方WebService
本实例基于CXF2.2+Spring2.0,使用MyEclipse8.5实现了CXF与Spring的整合开发。
cxf为spring注入webservice,很详细的技术整合,
linux环境下,cxf整合spring发布webservice源码