周末学习了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...
在IT行业中,CXF是一个广泛使用的开源框架,用于构建和部署Web服务。它结合了Apache CXF和Spring框架,提供了一种...总之,"CXF+Spring接口实例"是一个很好的学习资源,可以帮助开发者提升在Web服务领域的专业技能。
通过这个实例,你将学习到如何利用CXF和Spring的强大力量来构建高效、灵活的Web服务。理解并掌握这一技术,对于提升你的Java EE开发能力,特别是涉及到分布式系统和跨应用数据交换时,是非常有帮助的。
本实例将详细介绍如何使用CXF和Spring结合来创建一个Web服务。 1. **CXF简介**: CXF全称为Apache CXF,是一个开源的Web服务框架,它支持SOAP、RESTful等多种通信方式,并且能够生成和消费WSDL(Web服务描述语言)...
此示例项目虽然注释不够详细,但通过运行和调试,你可以深入理解CXF和Spring如何协同工作,这对于学习和实践SOA(面向服务架构)非常有帮助。同时,由于项目能够正常运行,对于初学者来说,这是一个很好的学习起点。
web项目使用spring和cxf的一个开发实例,有简单的代码样例和jar。是一个完整的项目,最终发布完成时访问 http://ip:port/项目名称/webservices/ 就会发现你发布的webservice服务。
使用CXF的`JaxWsProxyFactoryBean`,通过Spring配置来实例化服务客户端。设置服务URL和其他必要属性,例如,如果服务使用了WS-Security,可以配置安全策略。 4. **依赖注入**: 在Spring配置文件中,将客户端代理...
- 配置Spring上下文:在Spring配置文件中声明CXF的Bus实例,以及服务接口和服务实现类。这可以通过使用`<jaxws:endpoint>`或`<jaxrs:server>`标签来完成。 ```xml ``` - 使用Spring自动装配:通过`@...
这里少了一个类,是根据实体类生成xml的文件下载地址为:http://download.csdn.net/detail/qq_14996421/9495688
【标题】:“CXF + Spring 3.0的学习例子” 在IT行业中,Apache CXF是一个广泛使用的开源服务框架,它允许开发人员构建和部署各种Web服务。与Spring 3.0框架结合使用时,可以创建出高效且灵活的SOA(Service-...
Spring的ApplicationContext加载CXF的服务,使服务实例化、配置和管理变得更加简单。同时,Spring的事务管理可以与CXF服务无缝集成,确保服务操作的事务一致性。 4. jar包解析: 压缩包中的jar文件可能包括了CXF的...
本实例将详细阐述如何利用CXF和Spring来构建Web服务的客户端和服务端。 一、CXF简介 CXF是一个开源的Java框架,专门用于构建和消费Web服务。它支持SOAP、RESTful等多种服务模型,并且可以方便地与Spring框架集成,...
【标题】"cxf+spring webservice server demo"是一个基于Apache CXF和Spring框架构建的Web服务服务器端示例项目。这个项目展示了如何将CXF与Spring集成,以创建、部署和运行一个高效的Web服务。 【描述】指出,由于...
【标题】"CXF+Spring+Tomcat发布WebService"涉及的是使用Apache CXF框架与Spring框架结合,在Tomcat服务器上部署和消费Web服务的过程。这是一个常见的企业级应用开发场景,特别是对于实现基于SOAP协议的Web服务。...
【标题】"CXF+Spring 无包"指的是在不依赖特定打包工具(如Maven或Gradle)的情况下,利用Apache CXF和Spring框架构建Web服务的实例。Apache CXF是一个开源服务框架,它允许开发者创建和消费各种Web服务,包括SOAP和...
标题“简单cxf+spring构建webservice服务”指的是使用Apache CXF框架与Spring框架结合来创建Web服务。Apache CXF是一个开源的Java框架,它允许开发者创建和消费各种Web服务,包括SOAP和RESTful风格。Spring框架则为...
在CXF和Spring结合的场景下,Spring可以用来管理CXF的服务实例,从而简化服务的生命周期管理。 在"CXF+Spring实现Web服务工程"的实践中,通常会遵循以下步骤: 1. **配置Spring**:创建Spring配置文件,定义服务...
CXF通过Spring进行集成,可以方便地在Spring容器中管理服务实例。 2. **Spring框架**:Spring是Java平台上的一个核心框架,提供了诸如IoC(Inversion of Control,控制反转)、AOP(Aspect-Oriented Programming,...
发布CXF+Spring整合的REST的服务接口完整实例,其中包括数据库连接池,json数据格式传递数据,HttpURLConne的get和post方式调用接口,以及获取访问者ip地址工具类等众多的技术实例。