cxf+spring发布webservice服务(服务器端)

创建需要暴露到webservice的接口及其实现

@WebService
public interface HelloWorld {

	public String sayHello(String name);
	
}
@WebService
public class HelloWorldImpl implements HelloWorld {

	@Override
	public String sayHello(String name) {
		System.out.println("SayHello is called for " + name);
		return "Hello " + name;
	}
}

在WEB-INF下新建beans.xlm文件

<?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-3.0.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="com.spg.testCxfSpring.impl.HelloWorldImpl"
		address="/Hello" />
	 
	<!-- 
	<bean id="hello" class="com.spg.testCxfSpring.impl.HelloWorldImpl" />
	<jaxws:endpoint
		id="helloWorld"
		implementor="#hello"
		address="/Hello"
	 />
	 -->
	
</beans>

其中import为引入cxf的配置

<jaxws:endpoint>标签配置cxf服务器数据,其中address采用相对地址

接下来配置web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/beans.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>
  </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>

添加监听器,servlet配置等

此时服务器端已经发布成功,部署到tomcat中,启动tomcat,在浏览器中访问wsdl,http://localhost:8080/cxf-Spring-server/Hello?wsdl,成功访问说明webservice已经成功发布。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值