使用Fegin 做客户端,去注册中心 concul 找到对应服务然后调用!搞了我好一会儿
1.先进行jia导入
- 能进行 concul 配置扫码的config
- 能开启FeginClient 的core 和 springCloud(ribbon)支持
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-consul-all</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign-core</artifactId>
<version>${spring-cloud-openfeign-core.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>${spring-cloud-starter-openfeign.version}</version>
</dependency>
2.进行配置
加入bootStap.yml 文件,和application.properties文件同目录
spring:
profiles: local
cloud:
consul:
host: 47.110.91.2
port: 30001
discovery:
register: true
instance-id: ${spring.application.name}:${spring.profiles.active}:${port}
3.开启注解支持
@EnableFeignClients(basePackages = {"你的API接口包位置"})