您的位置:首页 > 其它

使用CXF创建webService服务端

2014-03-11 13:55 316 查看
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 {

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: