读书人

Spring+CXF 全引文版

发布时间: 2012-06-26 10:04:13 作者: rapoo

Spring+CXF 全注解版

1.Spring+CXF 全注解版 搭建 Spring3.1.1 CXF 2.5.2

?

2.部分配置

1)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"><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><context-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext-*.xml</param-value></context-param><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>/ws/*</url-pattern></servlet-mapping></web-app>

?

?2)applicationContext-cxf.xml

?

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context"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://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.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" /><context:component-scan base-package="com.j4t.demo.ws" /><bean id="webServicesAgent" name="code">package com.j4t.demo.ws;import javax.jws.WebService;//接口@WebServicepublic interface IHelloService {public String sayHello(String username);}package com.j4t.demo.ws;import javax.jws.WebService;import org.springframework.stereotype.Component;//实现@Component@WebService(serviceName = "helloService", endpointInterface = "com.j4t.demo.ws.IHelloService")public class HelloService implements IHelloService {public String sayHello(String username) {return username+"! Welcome to CXF in Method[HelloService sayHello]";}}

?3)客户端

服务地址:http://192.168.1.100:8080/Demo_Spring_CXF_Annotation/ws

client调用代码

?

DynamicClientFactory dcf = DynamicClientFactory.newInstance();Client client = dcf.createClient("http://192.168.1.100:8080/Demo_Spring_CXF_Annotation/ws/helloService?wsdl");Object[] reply = client.invoke("sayHello", new Object[] { "just4it" });System.out.println(reply[0]);
?

?

为什么我导入你的项目有错误呢? 为什么我导入你的项目有错误呢?
我写Demo的IDE 是myeclipse ...你可以自己新建个 干净的Web项目 再把文件 一个一个 覆盖掉就行了.. 为什么我导入你的项目有错误呢?
我写Demo的IDE 是myeclipse ...你可以自己新建个 干净的Web项目 再把文件 一个一个 覆盖掉就行了..
好的,谢谢,我试试,有问题在联系你,

读书人网 >软件架构设计

热点推荐