- 创建新的Module名为
feign-api并引入依赖
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
</dependency>
</dependencies>
- 配置文件yml
feign:
client:
config:
# default代表全局,也可改成xxxservice表示针对某服务的日志级别
default:
loggerlevel: BASIC
# 对feign启用httpclient的连接池
httpclient:
enabled: true
max-connections: 100
max-connections-per-route: 50
-
将之前模块中需要的实体类和接口移动到
feign-api里,client表示需要对外暴露的接口,pojo是对应的返回类型

-
在需要进行远程调用的项目的pom中加入这个
feign-api的依赖。注意这个groupId就是这个创建项目时填入的gruopId,artifactId则是模块名称
<dependency>
<groupId>cn.itcast.demo</groupId>
<artifactId>feign-api</artifactId>
<version>1.0</version>
</dependency>
- 删除原项目中的冗余接口和实体类
- 在需要进行远程调用的项目的启动类上加上注解
@EnableFeignClients(basePackages = "调用接口的全类名如cn.itcast.feign.clients") - 进行调用
892

被折叠的 条评论
为什么被折叠?



