Apache CXF实战之二 集成Sping与Web容器[转载]

By | 2015年3月9日

书接上文,下面看看CXF怎样和spring集成。

1.创建HelloWorld 接口类
package com.googlecode.garbagecan.cxfstudy.helloworld;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

@WebService
public interface HelloWorld {
@WebMethod
@WebResult String sayHi(@WebParam String text);
}
2.创建HelloWorld实现类
package com.googlecode.garbagecan.cxfstudy.helloworld;

public class HelloWorldImpl implements HelloWorld {

public String sayHi(String name) {
String msg = "Hello " + name + "!";
return msg;
}
}
3.修改web.xml文件

cxfstudy


cxf
org.apache.cxf.transport.servlet.CXFServlet
1


cxf
/ws/*

org.springframework.web.context.ContextLoaderListener

contextConfigLocation classpath*:**/spring.xml

4.创建spring配置文件并放在classpath路径下









5.创建测试类

package com.googlecode.garbagecan.cxfstudy.helloworld;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringClient {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
HelloWorld helloworld = (HelloWorld)context.getBean("helloworldClient");
System.out.println(helloworld.sayHi("kongxx"));
}
}
6.测试

6.1 首先启动tomcat或者使用maven的jetty,并访问http://localhost:9000/ws/HelloWorld?wsdl来验证web service已经启动并且生效;

6.2 然后运行测试类来验证web service。

原文链接:http://blog.csdn.net/kongxx/article/details/7525481

发表评论