yangcctv 发表于 2017-1-5 08:47:34

Web Service:Apache CXF 测试demo

web.xml配置

<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>/wbs/*</url-pattern>
</servlet-mapping>

测试类接口


import javax.jws.WebService;

@WebService
public interface HelloWorld {
public String sayHello(String name);
//cxf好像只支持string
//public List<Date> getDate(Map<String, String> map);
}

测试类接口实现类

import javax.jws.WebService;
import org.symbol.web.service.def.HelloWorld;
//http://localhost:8080/cas/wbs/HelloWord?wsdl
@WebService(endpointInterface="org.symbol.web.service.def.HelloWorld")
public class HelloWorldImpl implements HelloWorld{
public String sayHello(String name) {
return "hello!"+name;
}

}

spring xml

<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 Apache CXF Bean Definition -->
<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"/>
<!-- ************************************************************************************ -->
<!-- ******************web Service配置       ************************ -->
<!-- ************************************************************************************ -->
<!-- service -->
<jaxws:endpoint id="hellworld"
address="/HelloWord"
implementor="com.xxoo.web.service.impl.HelloWorldImpl"
>
</jaxws:endpoint>
</beans>

通过http://localhost:8080/${webappName}/wbs/HelloWord?wsdl查看wsdl
通过附件里的批处理文件生成客户端java类,该工具来自http://www.iteye.com/topic/746819
页: [1]
查看完整版本: Web Service:Apache CXF 测试demo