如何使用HSF
2015-10-24 11:35
281 查看
应用场景:B项目需要访问A项目的某些接口
一、A项目:
1.在pom.xml中添加hsf
<dependency> <groupId>com.taobao.hsf</groupId> <artifactId>hsf.app.spring</artifactId> <version>2.1.0.8</version> </dependency>
2.创建一个子项目api,只写需要向外提供的接口以及需要的bean:
package com.tiro.api; public interface UserClientAPI { List<User> listUser(); }3.在另一个子项目biz中,在pom.xml中添加api项目,并实现api中的接口:
<dependency> <groupId>com.tiro</groupId> <artifactId>api</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency>
package com.tiro.api.impl; public class UserClientAPIImpl implements UserClientAPI { List<User> listUser(){ //实现代码 } }4.创建spring配置文件spring-hsf-provier.xml,添加接口到hsf服务中,配置文件如下:
<?xml version="1.0" encoding="UTF-8" ?> <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd" default-autowire="byName"> <bean id="userClientAPIImpl" class="com.tiro.api.impl.UserClientAPIImpl"/> <bean id="useerClientAPIProvider" class="com.taobao.hsf.app.spring.util.HSFSpringProviderBean" init-method="init"> <property name="serviceInterface"> <value>com.tiro.api.UserClientAPI</value> </property> <property name="target"> <ref bean="userClientAPIImpl"/> </property> <property name="serviceName"> <value>userClientAPIService</value> </property> <property name="serviceVersion"> <value>1.0.0.daily</value> </property> </bean> </beans>5.在webx.xml中导入该配置文件:
<beans:import resource="spring-hsf-provider.xml" />6. 将子项目api发布到中央仓库: mvn deploy 7. 使用jerry运行项目,添加taobao-hsf.sar扩展。 二、项目B: 1.在pom.xml添加api项目:
<dependency> <groupId>com.tiro</groupId> <artifactId>api</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency>2.创建spring配置文件spring-hsf-consume.xml,从hsf服务中获取接口,配置文件如下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans default-autowire="byName"> <bean id="userClientAPI" class="com.taobao.hsf.app.spring.util.HSFSpringConsumerBean" init-method="init"> <property name="interfaceName" value="com.tiro.api.UserClientAPI" /> <property name="version"> <value>1.0.0.daily</value> </property> </bean> </beans>3.在webx.xml中导入该配置文件:
<beans:import resource="spring-hsf-consume.xml" />4.这样你就可以在项目中直接使用userClientAPI接口了。 三、参考: http://googi.iteye.com/blog/1884754
相关文章推荐
- 如何使用eclipse创建Maven版本的hsf工程及其子模块
- 如何在VC++中使用注册表
- 如何使用 Windows NT boot loader 来启动 Linux
- 如何使用Log4j?
- [导入]如何使用Visual C++调试程序?
- 如何使用C#创建一个三层的数据库应用程序
- 如何使用DELPHI和要SQL SERVER数据库连接
- 如何使用 Ehlib 实现自动排序
- 如何使用 VB 编写自动反安装的程序?
- 如何有效的使用对话框之二
- Access 中如何使用 ADO 來压缩或修复 MS Access 文件?
- 如何在SQL语句中使用正则表达式
- [翻译]如何组织使用模版技术的源代码
- 如何使用VS.NET调试数据库存储过程
- 如何使用BQYAHOO共享文件
- 如何使用线程
- 如何制作和使用帮助文件
- More Effective C++ Item M34:如何在同一程序中混合使用C++和C
- 应用WSDK -附录如何使用SOAP Trace Utility进行调试
- 如何在程序中使用自己的库单元