Tibco GI+CXF2.3.1+Spring3.0整合示例
1.导入Spring和CXF的所有依赖包
2.在web.xml中配置Spring和CXF
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/applicationContext-*.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>/services/*</url-pattern> </servlet-mapping>
<import resource="classpath:services.xml" />
@WebServicepublic interface IUserBiz {public User getFirstUser();}@WebService(endpointInterface="com.founder.core.biz.IUserBiz")public class UserBizImpl implements IUserBiz{private IUserDao userDao;public IUserDao getUserDao() {return userDao;}public void setUserDao(IUserDao userDao) {this.userDao = userDao;}public User getFirstUser() {return userDao.getFirstUser();}}public interface IUserDao {public User getFirstUser();}public class UserDaoImpl implements IUserDao{public User getFirstUser() {User user = new User();user.setId(1L);user.setUserName("****");user.setPassword("123");user.setGender(true);user.setAge(24);user.setEmail("****@sina.com");return user;}}<bean id="userDao" />
<?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.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="UserBiz" address="/UserBiz" ><jaxws:implementor> <bean class="com.core.biz.Impl.UserBizImpl"> <property name="userDao"> <ref bean="userDao"/> </property> </bean> </jaxws:implementor></jaxws:endpoint></beans>