使用CXF创建webService服务端

web.xml

<?xml version="1.0" encoding="UTF-8"?>
-<web-app xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" version="3.0">-<context-param><param-name>contextConfigLocation</param-name><param-value> /WEB-INF/applicationContext*.xml </param-value></context-param>
<!-- web应用启动时加载Spring容器 -->
-<listener><listener-class> org.springframework.web.context.ContextLoaderListener </listener-class></listener>
<!-- 表明所有来自/WebService/*请求,都交给 CXFServlet处理-->
-<servlet><servlet-name>cxf</servlet-name><servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class></servlet>-<servlet-mapping><servlet-name>cxf</servlet-name><url-pattern>/app5r/*</url-pattern></servlet-mapping></web-app>

 

applicationContext.xml

<?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"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd
">

<!-- web应用的类加载路径有两类
1>WEB-INF/classes目录
2>WEB-INF/lib目录
-->
<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 implementor="com.relonger.app5r.service.impl.UserServiceImpl" address="/UserWebService"></jaxws:endpoint>
</beans>

 

UserService.java

@WebService
@SOAPBinding(style = Style.RPC)
public interface UserService {

/**
* 判断用户登录,根据登录情况返回不同的信息
* @param userName 用户名
* @param passWord 密码
* @return 返回登录的不同情况
*/
public String login(@WebParam(name="mobile")String mobile, @WebParam(name="passWord")String passWord);

}

 

UserServiceImpl.java

@Component("userService")
@Transactional(readOnly = false, rollbackFor = Exception.class)
@WebService(endpointInterface="com.relonger.app5r.service.UserService",serviceName="UserServiceWs")
public class UserServiceImpl implements UserService {

}

使用CXF创建webService服务端,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。