这特么是啥系列之----HSF求求你别秀了

如何发布HSF服务

感觉这个hsf需要pandora环境,所以...先导依赖

<dependencyManagement>
    <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.5.9.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>com.taobao.pandora</groupId>
            <artifactId>pandora-boot-starter-bom</artifactId>
            <version>2018-01-release</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependency>
    <groupId>com.alibaba.boot</groupId>
    <artifactId>pandora-hsf-spring-boot-starter</artifactId>
</dependency>

配置...

在 application.properties 添加所有 HSF的默认版本信息和客户端超时信息, 样例配置如下:

spring.hsf.group=HSF
spring.hsf.version=1.0.0.DAILY
spring.hsf.timeout=3000
@SpringBootApplication

public class DemoApplication{
    public static void main(String[] args) {
        PandoraBootstrap.run(args);
        SpringApplication.run(DemoApplication.class, args);
        PandoraBootstrap.markStartupAndWait();
    }
}

@HSFProvider

注意是com.alibaba.boot.hsf.annotation.HSFProvider,不是com.taobao.hsf.app.spring.util.annotation.HSFProvider

编写你的HSF服务, 只需要在要发布的服务实现上添加 @HSFProvider, 其中 serviceInterface 是要发布服务的接口:

@HSFProvider(serviceInterface = DemoService.class)
public class DemoServiceImpl implements DemoService{}

可以使用 @HSFProvider 为特定的服务覆盖全局默认配置, 如:

@HSFProvider(serviceInterface = DemoService.class, serviceGroup = "HSF", serviceVersion = "1.0.1", clientTimeout = 500)
public class DemoServiceImpl implements DemoService{}

@HSFProvider 中的 serviceGroup 和 serviceVersion 以及其他 String 类型的配置都可以支持 Spring 的 property placeholder, 如:

@HSFProvider(serviceInterface = DemoService.class, serviceGroup = "${service.group.name}")
public class DemoServiceImpl implements DemoService{}

注意:spring boot默认只扫描main函数所在的package。如果服务是在其它的package里,需要配置@ComponentScan

@ComponentScan(basePackages = "com.taobao.mypackage")

然后呢...就是消费这个服务了

启动类要配置注解..

 
@SpringBootApplication

使用传统的 XML 方式装配 HSF Spring Bean。

创建一个 Spring 配置文件,如 src/main/resources/hsf-consumer.xml,表示要引用相关的hsf的服务。内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean id="helloWorldConsumer" class="com.taobao.hsf.app.spring.util.HSFSpringConsumerBean" init-method="init">
        <property name="interfaceName" value="com.acme.DemoService"/>
        <property name="version" value="1.0.0.daily"/>
        <property name="group" value="HSF"/>
    </bean>
</beans>

在Spring Boot Application类上添加 @ImportResource 导入自定义的 hsf-consumer.xml 文件,这样spring hsf服务对应的bean就会被初始化.

@ImportResource({"classpath:hsf-consumer.xml"})
@SpringBootApplication
public class DemoApplication {}

接下来就是在代码中直接引入HSF服务的接口类,代码如下:

@Autowired
DemoService demoService;
嗯嗯嗯,会发布服务,消费服务就行,不会再看api










  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值