通过url调试发布的cxf webservice

一。在web.xml中配置cxf 注意<url-pattern>/ws/*</url-pattern>配置,cxf会拦截此类url,进行处理
	<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>/ws/*</url-pattern>
	</servlet-mapping>

二 写要发布的接口及其实现类
@WebService
public interface UserWebService {
	public SSOUser getSSOUser(String ticket);
}

//这儿的targetNamespace 一定要包含 /ws 
@WebService(endpointInterface = "com.suantop.sso.ws.UserWebService", targetNamespace = "http://localhost:8080/sso/ws") 
public class UserWebServiceImpl implements UserWebService {
	
	public SSOUser getSSOUser(String ticket){
		RegisterUser ru = UserCenter.get(ticket);
		if(ru != null){
			return new SSOUser(ru.getId(), ru.getPassword());
		}
		return null;
	}
}

三 写spring配置文件
<?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-2.5.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"
	default-autowire="byType" default-lazy-init="true">
	
	<import resource="classpath:META-INF/cxf/cxf.xml" />
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
	
	<!-- jax-ws endpoint定义 -->
	<jaxws:endpoint id="userWebServiceEP" address="/UserService">
		<jaxws:implementor ref="userWebService" />
	</jaxws:endpoint>
	
	<!-- 实现WebService的bean -->
	<bean id="userWebService" class="com.suantop.sso.ws.UserWebServiceImpl" />
</beans>



Ok 启动tomcat
输入url:http://localhost:8080/sso/ws/UserService?wsdl
会出wsdl文件
发布成功

你可能感兴趣的:(spring,Web,xml,webservice,SSO)