标签:
下面是:beanContext-spring-cxf.xml 中的配置;(一定要注意顶部引入的beans里面的spring 配置一定要和你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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" 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://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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" /> <!-- 配置userWs --> <bean id="userWs" class="com.flmk.urms.cxf.impl.UserLoginServiveImpl"> <property name="userService" ref="userService" /> </bean> <!-- 要暴露给外部调用的接口,address:请求路径 --> <jaxws:endpoint implementor="#userWs" address="/userLogin"></jaxws:endpoint> </beans>
Web.xml 中的配置(一定记得在里面添加这么一段,不然启动报错哟。);
<servlet> <servlet-name>CXFService</servlet-name> <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> <load-on-startup>30</load-on-startup> </servlet> <servlet-mapping> <servlet-name>CXFService</servlet-name> <url-pattern>/ws/*</url-pattern> </servlet-mapping>
还有就是jar包的问题,这个网上到时一大堆都有也可以在官网去下载:http://cxf.apache.org/download.html
cxf-2.3.3.jar
geronimo-annotation_1.0_spec-1.1.1.jar
geronimo-jaxws_2.2_spec-1.0.jar
geronimo-stax-api_1.0_spec-1.0.1.jar
geronimo-ws-metadata_2.0_spec-1.1.3.jar
jaxb-api-2.2.1.jar
jaxb-impl-2.2.1.1.jar
neethi-2.0.4.jar
wsdl4j-1.6.2.jar
XmlSchema-1.4.7.jar
wstx-asl-3.2.9.jar
以上包是基本最少而且缺一不可的。其它包仅需求再加。
下面是接口的具体写法:
package com.flmk.urms.cxf; import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebService; import com.flmk.urms.entity.TUser; @WebService public interface UserLoginServiceI { @WebMethod public TUser userLogin(@WebParam(name="userName") String userName,@WebParam(name="passWord") String passWord); }
接口实现类的写法:
package com.flmk.urms.cxf.impl; import javax.annotation.Resource; import javax.jws.WebService; import org.springframework.beans.factory.annotation.Autowired; import com.flmk.urms.core.user.service.UserService; import com.flmk.urms.cxf.UserLoginServiceI; import com.flmk.urms.entity.TUser; @WebService public class UserLoginServiveImpl implements UserLoginServiceI{ @Autowired private UserService userService; @Resource public void setUserService(UserService userService) { this.userService = userService; } @Override public TUser userLogin(String userName, String passWord) { return userService.userAuthenticate(userName, passWord); } }
基本上就是以上这些配置了,再次记录以便以后忘记。。O(∩_∩)O~
在S2SH中添加Web Service(CXF),怎么CXF集成SSH
标签:
原文地址:http://my.oschina.net/yang5610/blog/501608