CXF 结合 Spring 实现 WebService
一、定义服务接口
package com.cxf.server;
import javax.jws.WebService;
@WebService
public interface Hello {
String SayHi(String text);
}
二、实现服务接口
package com.cxf.server;
import javax.jws.WebService;
@WebService(endpointInterface="com.cxf.server.Hello")
public class HelloImpl implements Hello {
@Override
public String SayHi(String text) {
//System.out.println("客户端传值是:"+text);
int n = text.indexOf(" ");
text = text.substring(n+1, text.length());
return "你好 " + text;
}
}
三、配置 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-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<bean id="hello" class="com.cxf.server.HelloImpl" />
<jaxws:endpoint id="hellows" implementor="#hello" address="/Hello" />
</beans>