费话少话 实例如下(包自己导自己建):
服务端:
1 服务接口
@WebService
public interface HelloWorld {
public String sayHello(String text);
}
2 服务实现类
@WebService(endpointInterface = "org.shenhongwei.dao.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
/*
* (non-Javadoc)
*
* @see org.shenhongwei.dao.HelloWorld#sayHello(java.lang.String)
*/
public String sayHello(String text) {
return "Hello" + text;
}
}
3 spring配置文件beans.xml 这里放置于WEB-INF下:
<?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-2.0.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" />
<bean id="hello" class="org.shenhongwei.dao.impl.HelloWorldImpl" />
<jaxws:endpoint id="helloWorld" implementor="#hello"
address="/HelloWorld">
</jaxws:endpoint>
</beans>
4 web.xml文件的配置
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/beans.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>
部署到tomcat下 启动服务 访问http://localhost:8050/cxf_spring/HelloWorld?wsdl
客户端
1 接口类
@WebService
public interface HelloWorld {
public String sayHello(String text);
}
2 spring beans.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-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="client" class="org.shenhongwei.inter.HelloWorld"
factory-bean="clientFactory" factory-method="create">
</bean>
<bean id="clientFactory"
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass"
value="org.shenhongwei.inter.HelloWorld">
</property>
<property name="address"
value="http://localhost:8050/cxf_spring/HelloWorld?wsdl" />
</bean>
</beans>
3 测试类Test
public class Test {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext(
"beans.xml");
HelloWorld client = (HelloWorld) ctx.getBean("client");
String result = client.sayHello("你好!");
System.out.println(result);
}
}
OK
也可以写成非依赖注入式访问Test
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
JaxWsProxyFactoryBean j=new JaxWsProxyFactoryBean();
j.setAddress("http://localhost:8050/cxf_spring/HelloWorld?wsdl");
j.setServiceClass(org.shenhongwei.dao.HelloWorld.class);
HelloWorld hw=(HelloWorld) j.create();
System.out.println(hw.sayHello("ppp"));
// TODO Auto-generated method stub
}
}
分享到:
相关推荐
cxf+spring实现webservice
cxf+spring+client+springmvc
cxf+spring+tomcat 只是演示,一个helloWorld的例子
简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar简单的webservice+Cxf+Spring数据对接实例以及jar.rar...
代码是我一行行敲的,直接部署就能用,service,client端实现了:(cxf用的是3.0最新的) 1维数组, 2维数组, 3维数组, List, List , Map(adapter方式实现的), 直接返回bean, 返回object[], 做了header的安全认证校验.
CXF+spring+struts实现WebService
内容为CXF整合spring的服务端和客户端开发例子,注释不太详尽,网上的教程比较多,但是多跑不起来,特地把整个工程都打包给大家做参考,程序内容均来自网上整理,均可以运行。
cxf+spring整合,只要把项目导入到myeclipse中,就可以运行。
CXF+Spring+Tomcat发布WebService
web项目使用spring和cxf的一个开发实例,有简单的代码样例和jar。是一个完整的项目,最终发布完成时访问 http://ip:port/项目名称/webservices/ 就会发现你发布的webservice服务。
这是我在使用cxf+spring进行开发中的一点总结,如何搭建开发环境、如何配置dao使用,如何解决乱码问题等的经验分享
cxf+spring开发所必备的jar包压缩包
基于CXF的WebService服务端和客户端示例,CXF+Spring,希望能为WebService开发者提供帮助。WebService,CXF,Spring.
基于maven的cxf+spring简单demo,spring版本为4.1.6,cxf版本为3.0.8
cxf+spring开发webservice的简单实例,通过查看cfx的doc文档确定wsdl支持所引用的最少jar包
这里少了一个类,是根据实体类生成xml的文件下载地址为:http://download.csdn.net/detail/qq_14996421/9495688
CXF+Spring+MyBatis+Maven项目整合,包含服务端和客户端。
使用cxf+spring框架开发webservice的客户端与服务端代码,用于连接两个项目
cxf+spring+hibernate整合添加功能实现修改版是对完整版的修正,有兴趣的同学可以下载研究一下。
cxf+spring 实现websevice的maven项目,此例子简单,易懂,对刚接触cxf webservice的非常有帮助!