刚起步时实际上服务端是最简单的。
一、加入cxf支持
简单的说就是创建一个web项目,并将cxf的发布包和相关依赖包放到web工程的lib目录下。我选择的cxf版本是2.2.5
二、创建webservice服务接口和实现类
1、创建服务接口,全例如:
2、创建web服务接口的实现类
三、配置spring,对外发布web serive
四、配置web.xml
五、发布应用及服务
即将web项目发布到tomcat之类的web应用服务器中。运行即可。
要想知道我们的web服务是否成功发布,可以访问以下地址:
http://localhost:8080/appname/HelloWorld?wsdl
如果能成功展现xml形式的描述文件(如下图),则发布成功。反之,没有成功。
[img]http://dl.iteye.com/upload/attachment/187239/5b542b7f-3d24-3a99-84a5-a0d99e53bd20.gif[/img]
一、加入cxf支持
简单的说就是创建一个web项目,并将cxf的发布包和相关依赖包放到web工程的lib目录下。我选择的cxf版本是2.2.5
二、创建webservice服务接口和实现类
1、创建服务接口,全例如:
package cn.ibeans.cxf.server;
import javax.jws.WebService;
@WebService
public interface HelloWorld {
String sayHello(String msg);
}
2、创建web服务接口的实现类
package cn.ibeans.cxf.server;
import javax.jws.WebService;
@WebService(endpointInterface="cn.ibeans.cxf.server.HelloWorld")
public class HelloWorldImpl implements HelloWorld {
public String sayHello(String msg) {
System.out.println("客户端的传值为: "+msg);
return "你好! "+msg;
}
}
三、配置spring,对外发布web serive
<?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: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">
<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" />
<jaxws:endpoint id="helloWorld" implementor="cn.ibeans.cxf.server.HelloWorldImpl" address="/HelloWorld"/>
</beans>
四、配置web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
五、发布应用及服务
即将web项目发布到tomcat之类的web应用服务器中。运行即可。
要想知道我们的web服务是否成功发布,可以访问以下地址:
http://localhost:8080/appname/HelloWorld?wsdl
如果能成功展现xml形式的描述文件(如下图),则发布成功。反之,没有成功。
[img]http://dl.iteye.com/upload/attachment/187239/5b542b7f-3d24-3a99-84a5-a0d99e53bd20.gif[/img]