- 浏览: 47347 次
- 性别:
- 来自: 重庆
文章分类
最新评论
使用CXF,spring部署Web Service服务
server 实现
步骤一 新建Web工程
步骤二 下载cxf包(地址:http://www.apache.org/dyn/closer.cgi?path=/cxf/2.6.2/apache-cxf-2.6.2.tar.gz)
步骤三 解压cxf包,将apache-cxf-*.*.*/lib目录下的jar包复制到Web工程->WebRoot->WEB-INF->lib文件夹下(cxf已经整合了spring所以不需要在导入spring的包了)。不必导入全部jar包 具体见附件图片
步骤四 在Web工程下创建一个接口并定义一个方法
例:
package com.cxf;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public interface ISayHello
{
public String sayHello(@WebParam(name="name")String name);
}
步骤五 新建一个类继承接口
例:
package com.cxf;
import javax.jws.WebService;
@WebService(endpointInterface = "com.cxf.ISayHello")
public class SayHelloImpl implements ISayHello
{
@Override
public String sayHello(String name)
{
return "my name is " + name;
}
}
步骤六 在工程src目录下创建spring配置文件applicationContext.xml
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: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/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="sayHelloImpl" class="com.cxf.SayHelloImpl" />
<jaxws:endpoint id="sayHello" implementor="#sayHelloImpl" address="/sayHello" />
</beans>
步骤七 修改Web工程->WebRoot->WEB-INF->web.xml
在web.xml文件<web-app></web-app>中加上:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>/*</url-pattern>
</servlet-mapping>
发布我们新建的Web工程
打开浏览器访问:http://localhost:8080/WebService/
client 实现
步骤一 在工程中新建一个类(可以重新建一个工程但需要导入cxf的相关包)
例:
package com.cxf.client;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.cxf.ISayHello;
public class CxfClient
{
public static void main(String[] args)
{
ClassPathXmlApplicationContext context
= new ClassPathXmlApplicationContext(new String[] {"com/cxf/client/applicationContext_client.xml"});
ISayHello client = (ISayHello)context.getBean("sayHello2");
String response = client.sayHello("Joe");
System.out.println("Response: " + response);
System.exit(0);
}
}
步骤二 在client同级目录新建client spring配置文件applicationContext_client.xml
applicationContext_client.xml文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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">
<!--
该方式访问ws服务也是利用spring的依赖注入法
id是spring IOC容器唯一标识符
serviceClass是webservices服务接口
address是服务wsdl地址
-->
<jaxws:client id="sayHello2" serviceClass="com.cxf.ISayHello" address="http://localhost:8080/WebService/sayHello?wsdl" />
</beans>
执行CxfClient的main方法
控制台打印
Response: my name is Joe
在完成实例中所遇问题
启动tomcat抛:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sayHello': Invocation of init method failed; nested exception is java.lang.LinkageError: JAXB 2.1 API is being loaded from the bootstrap classloader, but this RI (from jar:file:/D:/apache-tomcat-6.0.29/webapps/WebService/WEB-INF/lib/jaxb-impl-2.2.4-1.jar!/com/sun/xml/bind/v2/model/impl/ModelBuilder.class) needs 2.2 API. Use the endorsed directory mechanism to place jaxb-api.jar in the bootstrap classloader. (See http://java.sun.com/j2se/1.6.0/docs/guide/standards/)
Caused by: java.lang.LinkageError: JAXB 2.1 API is being loaded from the bootstrap classloader, but this RI (from jar:file:/D:/apache-tomcat-6.0.29/webapps/WebServiceCXF/WEB-INF/lib/jaxb-impl-2.2.4-1.jar!/com/sun/xml/bind/v2/model/impl/ModelBuilder.class) needs 2.2 API. Use the endorsed directory mechanism to place jaxb-api.jar in the bootstrap classloader. (See http://java.sun.com/j2se/1.6.0/docs/guide/standards/)
问题原因:cxf与jdk jar包冲突
解决方法:
1.升级JDK到jdk1.6.0_25(据说jdk1.6.0_25后就支持了),然后修改tomcat的执行jdk版本(还有另一种方法,可以google下)
问题二:
执行客服端类main方法时抛:
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [demo/spring/client/client-beans.xml]; nested exception is javax.xml.parsers.FactoryConfigurationError: Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found
问题原因:
是我使用MyEclipse创建项目时引用了J2EE 1.4 Library Container库
解决方法:
1.删掉J2EE 1.4 Library 。
2.换为JAVA EE 5/6 Library
server 实现
步骤一 新建Web工程
步骤二 下载cxf包(地址:http://www.apache.org/dyn/closer.cgi?path=/cxf/2.6.2/apache-cxf-2.6.2.tar.gz)
步骤三 解压cxf包,将apache-cxf-*.*.*/lib目录下的jar包复制到Web工程->WebRoot->WEB-INF->lib文件夹下(cxf已经整合了spring所以不需要在导入spring的包了)。不必导入全部jar包 具体见附件图片
步骤四 在Web工程下创建一个接口并定义一个方法
例:
package com.cxf;
import javax.jws.WebParam;
import javax.jws.WebService;
@WebService
public interface ISayHello
{
public String sayHello(@WebParam(name="name")String name);
}
步骤五 新建一个类继承接口
例:
package com.cxf;
import javax.jws.WebService;
@WebService(endpointInterface = "com.cxf.ISayHello")
public class SayHelloImpl implements ISayHello
{
@Override
public String sayHello(String name)
{
return "my name is " + name;
}
}
步骤六 在工程src目录下创建spring配置文件applicationContext.xml
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: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/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="sayHelloImpl" class="com.cxf.SayHelloImpl" />
<jaxws:endpoint id="sayHello" implementor="#sayHelloImpl" address="/sayHello" />
</beans>
步骤七 修改Web工程->WebRoot->WEB-INF->web.xml
在web.xml文件<web-app></web-app>中加上:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>/*</url-pattern>
</servlet-mapping>
发布我们新建的Web工程
打开浏览器访问:http://localhost:8080/WebService/
client 实现
步骤一 在工程中新建一个类(可以重新建一个工程但需要导入cxf的相关包)
例:
package com.cxf.client;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.cxf.ISayHello;
public class CxfClient
{
public static void main(String[] args)
{
ClassPathXmlApplicationContext context
= new ClassPathXmlApplicationContext(new String[] {"com/cxf/client/applicationContext_client.xml"});
ISayHello client = (ISayHello)context.getBean("sayHello2");
String response = client.sayHello("Joe");
System.out.println("Response: " + response);
System.exit(0);
}
}
步骤二 在client同级目录新建client spring配置文件applicationContext_client.xml
applicationContext_client.xml文件内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="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">
<!--
该方式访问ws服务也是利用spring的依赖注入法
id是spring IOC容器唯一标识符
serviceClass是webservices服务接口
address是服务wsdl地址
-->
<jaxws:client id="sayHello2" serviceClass="com.cxf.ISayHello" address="http://localhost:8080/WebService/sayHello?wsdl" />
</beans>
执行CxfClient的main方法
控制台打印
Response: my name is Joe
在完成实例中所遇问题
启动tomcat抛:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sayHello': Invocation of init method failed; nested exception is java.lang.LinkageError: JAXB 2.1 API is being loaded from the bootstrap classloader, but this RI (from jar:file:/D:/apache-tomcat-6.0.29/webapps/WebService/WEB-INF/lib/jaxb-impl-2.2.4-1.jar!/com/sun/xml/bind/v2/model/impl/ModelBuilder.class) needs 2.2 API. Use the endorsed directory mechanism to place jaxb-api.jar in the bootstrap classloader. (See http://java.sun.com/j2se/1.6.0/docs/guide/standards/)
Caused by: java.lang.LinkageError: JAXB 2.1 API is being loaded from the bootstrap classloader, but this RI (from jar:file:/D:/apache-tomcat-6.0.29/webapps/WebServiceCXF/WEB-INF/lib/jaxb-impl-2.2.4-1.jar!/com/sun/xml/bind/v2/model/impl/ModelBuilder.class) needs 2.2 API. Use the endorsed directory mechanism to place jaxb-api.jar in the bootstrap classloader. (See http://java.sun.com/j2se/1.6.0/docs/guide/standards/)
问题原因:cxf与jdk jar包冲突
解决方法:
1.升级JDK到jdk1.6.0_25(据说jdk1.6.0_25后就支持了),然后修改tomcat的执行jdk版本(还有另一种方法,可以google下)
问题二:
执行客服端类main方法时抛:
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource [demo/spring/client/client-beans.xml]; nested exception is javax.xml.parsers.FactoryConfigurationError: Provider org.apache.xerces.jaxp.DocumentBuilderFactoryImpl not found
问题原因:
是我使用MyEclipse创建项目时引用了J2EE 1.4 Library Container库
解决方法:
1.删掉J2EE 1.4 Library 。
2.换为JAVA EE 5/6 Library
发表评论
-
jxl操作execl
2014-06-12 16:18 552jxl操作execljxl操作execljxl操作execlj ... -
jFreechart
2013-03-08 16:15 0jFreechart -
需要学习内容
2013-03-05 22:15 0技术问题: 1、spring框架的实现原理(ioc、aop ... -
JAVA NIO
2012-10-27 09:51 0JAVA NIO -
JAVA类加载
2012-10-26 16:06 0JAVA类加载 -
理解JVM
2012-10-26 16:06 0理解JVM -
理解HashMap,HashTable
2012-10-26 16:05 0理解HashMap,HashTable -
JMS ActiveMQ
2012-10-26 16:04 0JMS和WebService的区别? 1.WebService ... -
JAVA垃圾收集机制
2012-10-26 16:01 0... -
JAVA并发编程学习
2012-10-26 16:00 0java并发编程 -
ssh的优缺点整理
2012-09-22 16:13 0以前开发web应用程序的 ... -
java 复习
2012-09-12 14:31 0java的堆与栈 堆: 1、堆是一个运行时数据区,有new.. ... -
javascript实现图片预览
2012-07-31 15:22 0使用两种不同的方法实现图片预览功能 Java代码 &l ... -
使用JSONP完成HTTPS跨域请求
2012-04-02 21:26 26271使用JSONP完成HTTPS跨域请 ... -
部署WebService服务(cxf,spring)2
2012-03-29 18:30 0client 实现 步骤一 在工程中新建一个类(可以重新 ... -
部署WebService服务(Axis2,spring)2
2012-03-27 11:06 0步骤七 在Web工程->WebRoot目录下新建axis ... -
部署WebService服务(Axis2,spring)
2012-03-28 20:55 7070部署WebService(Axis2和spring集成) s ... -
部署WebService服务(Axis)
2012-03-24 16:44 1357Axis实现Axis server实现步骤一 创建Web工程 ...
相关推荐
webservice与spring整合学习文档,里面的项目部署上就可以使用
CXF对Interceptor拦截器的支持 CXF WebService中传递复杂类型对象 CXF整合Spring ANT工具快速构建、部署工程
Apache CXF是一个开源的Service框架,它实现了JCP与Web Service中一些重要标准。CXF简化了构造,集成,面向服务架构(SOA)业务组件...CXF设计成可灵活部署到各种容器中包括Spring-based,JBI,SCA, Servlet和J2EE容器。
一、Web Services、SOA简介。 二、CXF简介。 1、关于ApacheCXF。 2、功能特性。 3、CXF安装包下载及目录结构。 ...d、spring配置。 e、web应用配置。 f、应用部署。 g、启动服务。 h、消费服务。】
使用 CXF 做 webservice 简单例子...它允许创建高性能和可扩展的服务,您可以将这样的服务部署在 Tomcat 和基于 Spring 的轻量级容器中,以及部署在更高级的服务器上,例如 Jboss、IBM® WebSphere® 或 BEA WebLogic。
cxf+spring+jdk1.5开发webService部署weblogic9.2
简单的CXF(WebService)例子 打包后文件太大,故所需的jar文件自己下载 cxf版本:cxf-2.2.7 spring版本:spring2.5.6 例子简单,使用,部署即可运行。
Apache CXF 是一个开放源代码框架...它允许创建高性能和可扩展的服务,您可以将这样的服务部署在 Tomcat 和基于 Spring 的轻量级容器中,以及部署在更高级的服务器上,例如 Jboss、IBM® WebSphere® 或 BEA WebLogic。
使用CXF+spring创建一个web的接口项目源代码,Myeclipse创建,部署到tomcat中即可访问。 与此对应的博客地址为:http://blog.csdn.net/zxnlmj/article/details/28880303
Apache CXF 是一个开放源代码框架...它允许创建高性能和可扩展的服务,您可以将这样的服务部署在 Tomcat 和基于 Spring 的轻量级容器中,以及部署在更高级的服务器上,例如 Jboss、IBM® WebSphere® 或 BEA WebLogic。
apache CXF 是一个开放源代码框架...它允许创建高性能和可扩展的服务,您可以将这样的服务部署在 Tomcat 和基于 Spring 的轻量级容器中,以及部署在更高级的服务器上,例如 Jboss、IBM® WebSphere® 或 BEA WebLogic。
本示例演示了如何基于将Apache CXF与Spring Boot结合使用。 快速入门使用Spring Boot来配置一个小的应用程序,其中包括启用了Swagger的CXF JAXRS端点。 重要的 该快速入门可以在2种模式下运行:在您的计算机和...
cxf webservice 实例(包括服务端及客户端代码),亲测可用,项目采用spring与cxf结合的,附件解压后看到两个项目,分部是服务端项目和客户端项目,启动tomcat服务器部署后,通过客户端右键运行java 的 mian方法代码...
cxf webservice 实例(包括服务端及客户端代码),亲测可用,项目采用spring与cxf结合的,附件解压后看到两个项目,分部是服务端项目和客户端项目,启动tomcat服务器部署后,通过客户端右键运行java 的 mian方法代码...
Apache CXF 是一个开放源代码框架...它允许创建高性能和可扩展的服务,您可以将这样的服务部署在 Tomcat 和基于 Spring 的轻量级容器中,以及部署在更高级的服务器上,例如 Jboss、IBM® WebSphere® 或 BEA WebLogic。
tutorial-soap-spring-boot-cxf 教程如何使用 , 和创建,测试,部署,监视SOAP 接下来的每个步骤都基于前一个步骤。 因此,如果从第3步开始,则代码中将覆盖第1步和第2步。 步骤1-3:随博客文章一起发布: (或...
使用 spring 的 CXF Web 服务示例 使用 spring-boot 的 CXF Web 服务示例 调用上面两个网络服务的客户端 要生成客户端使用的类,请使用 mvn generate-sources(在 /target/generated 中生成的@WebServiceClient 类...
2. Wink Rest服务、Webservice服务:jaxws、CXF等 3. IO 流上传下载文件,多线程操作 4. 发送邮件,配置邮件服务器,发基于html、纯文本格式的邮件(可以免费赠送网络爬虫,使其群发邮件,做到广告推送等) 5. MD...
6.能够使用WebService、CXF技术,完成第三方服务开发; 7.熟练使用SVN和Git进行代码的版本控制; 8.熟练使用Maven来进行多模块项目的构建以及管理项目中依赖包,以及使用Maven最终完成项目的热部署; 9.熟悉junit技术...