读书人

Tibco GI+CXF2.3.1+Spring3.0调整示例

发布时间: 2012-12-22 12:05:06 作者: rapoo

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>


3.在applicationContext-common.xml中导入CXF的配置文件
    <import resource="classpath:services.xml" /> 


4.编写webService的demo程序
4.1 biz接口
@WebServicepublic interface IUserBiz {public User getFirstUser();}

4.2 biz实现
@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();}}

4.3 Dao接口
public interface IUserDao {public User getFirstUser();}

4.4 Dao实现
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;}}

4.5 在Spring的配置文件中配置Dao的Bean
<bean id="userDao" />

4.6 在CXF的配置文件中将biz类注册成webService服务,并整合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.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>

4.7 启动tomcat访问,CXF与spring整合,并发布服务成功
http://127.0.0.1:8000/Test_Cxf/services/UserBiz?wsdl
http://127.0.0.1:8000/Test_Cxf/services/UserBiz/getFirstUser

5.使用Tibco GI编写页面
5.1使用Tools->xml Mapping Utility配置WebService
5.2字段与from之间由Object->name 匹配
5.3使用Generate生成调用JS
5.4配置button触发事件

读书人网 >编程

热点推荐