周末学习了cxf发布webservice的例子,按照官网上的步骤进行配置,错误不断,经过一番折腾,终于成功了。
下面说说我的配置:
1.下载jar:
2.web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<!--
spring需要加载的配置文件
-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:com/zhengs/spring-cxf.xml
</param-value>
</context-param>
<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>/service/*</url-pattern>
</servlet-mapping>
</web-app>
3.spring-cxf.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:tx="http://www.springframework.org/schema/tx"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:cxf="http://cxf.apache.org/core"
xmlns:wsa="http://cxf.apache.org/ws/addressing"
xsi:schemaLocation="
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.1.xsd
http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd
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" />
<cxf:bus>
<cxf:features>
<!--日志拦截功能,用于监控soap内容,开发后可以删除 -->
<cxf:logging/>
<wsa:addressing/>
</cxf:features>
</cxf:bus>
<bean id="hello" class="com.zhengs.HelloWorldImpl" />
<jaxws:endpoint id="helloWorld" implementor="#hello" address="/HelloWorld" publish="true"/>
</beans>
4.webservice接口HelloWorld.java
package com.zhengs;
import javax.jws.WebService;
@WebService(targetNamespace="zhengs.com")
public interface HelloWorld {
String sayHi(String text);
}
实现:HelloWorldImpl.java
package com.zhengs;
import javax.jws.WebService;
@WebService(endpointInterface = "com.zhengs.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
public String sayHi(String text) {
return "Hello , " + text;
}
}
5加上log4j.properties文件,部署到tomcat6.0下面,在5.0.28下面测试过有异常
6.添加测试类Client.java
package com.zhengs.client;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.zhengs.HelloWorld2;
public final class Client {
private Client() {
}
public static void main(String args[]) throws Exception {
// START SNIPPET: client
ClassPathXmlApplicationContext context
= new ClassPathXmlApplicationContext("beans.xml");
HelloWorld2 client = (HelloWorld2)context.getBean("helloClient");
String response = client.sayHi("Joe");
System.out.println("Response: " + response);
System.exit(0);
// END SNIPPET: client
}
}
HelloWorld2.java可以用HelloWorld.java代替
结束。
代码打包,提供下载,lib包自行下载,提供网址:http://jarvana.com/jarvana/
- 大小: 47.8 KB
分享到:
相关推荐
简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar...
cxf+spring webService实例,用到的包自己导入吧!
cxf+spring开发webservice的简单实例,通过查看cfx的doc文档确定wsdl支持所引用的最少jar包
cxf+sprinp webservice实现带测试程序,以验证
web项目使用spring和cxf的一个开发实例,有简单的代码样例和jar。是一个完整的项目,最终发布完成时访问 http://ip:port/项目名称/webservices/ 就会发现你发布的webservice服务。
使用cxf+spring框架开发webservice的客户端与服务端代码,用于连接两个项目
这里少了一个类,是根据实体类生成xml的文件下载地址为:http://download.csdn.net/detail/qq_14996421/9495688
发布CXF+Spring整合的REST的服务接口完整实例,其中包括数据库连接池,json数据格式传递数据,HttpURLConne的get和post方式调用接口,以及获取访问者ip地址工具类等众多的技术实例。
NULL 博文链接:https://devon-k.iteye.com/blog/1136650
CXF2+Spring2.5开发WebService实例,需要导入jar包
cxf spring maven 实例 webservice
本实例是一个简单的Spring+Apache CXF+MyBatis+Maven的集成小项目,可以最为学习参考,程序说明在我的博客里面有,链接地址:http://blog.csdn.net/liuxing9345/article/details/77983755
利用CXF3.0+Spring3.2 HelloWorld实例,并且导入了小量的jar包以及在写例子的过程中遇见的一些错误!
1):含有spring-3.2.8.RELEASE.jar、velocity-tools-2.0.jar、velocity-1.7.jar、mybatis-spring-1.0.2.jar、mybatis-3.0.6.jar、cxf-api-2.2.9.jar等丰富的jar包。 2):采用spring3.2作为bean容器管理,...
利用CXF3.0.2+Spring3.2.14发布WSSecurity!需要源代码可以下载!
CXF结合spring项目实例,com.email.ws.impl包下为eclipse工具生成的客户端,text包用来测试
本实例基于CXF2.2+Spring2.0,使用MyEclipse8.5实现了CXF与Spring的整合开发。
配置好数据库,放到tomcat访问 http://localhost:8080/Service wsdl:http://localhost:8080/Service/hello?wsdl ...访问rest实例:http://localhost:8080/Service/rest/user/test/1 浏览器输出 hello 1
利用CXF3.0.2+Spring3.2.14传输文件,里面有笔者在练习过程中遇到的错误,还有源代码可以下载!