WebService服务端——CXF和Spring的整合

一、在Spring开发环境的基础上导入Jar包:
- cxf.jar
- commons-logging.jar
- neethi.jar
- XmlSchema.jar
- wsdl4j.jar

二、创建WebService接口

package com.demo;

import javax.jws.WebParam;
import javax.jws.WebService;

@WebService
public interface HelloWorld {
public String sayHi(@WebParam(name = "text") String text);
}

三、编写实现类

package com.demo;

import javax.jws.WebService;

@WebService(endpointInterface = "com.demo.HelloWorld", serviceName = "HelloWorld")
public class HelloWorldImpl implements HelloWorld {
public String sayHi(String text){
return "Hello "+text;
}
}

四、配置application-context.xml


default-autowire="byName"
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">





implementor="com.demo.HelloWorldImpl"
address="/helloWorld" />



五、web.xml中加入如下配置


CXFServlet

org.apache.cxf.transport.servlet.CXFServlet

1



CXFServlet
/webservice/*



六、启动Tomcat,访问[url]http://localhost:8080/YHPC/webservice/helloWorld?wsdl[/url]查看是否配置成功。

你可能感兴趣的:(Java,webservice)