需求场景:在基础资源服务新增某条数据时,同时也调用系统管理服务的接口插入一条数据。
第一步:在pom.xml引入feign
<!-- http client feign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
第二步:在主应用程序加上注解:@EnableFeignClients(basePackages = {"com.education.core.server.service.external"})
如:
@SpringBootApplication(scanBasePackages = {"com.education.server", "com.ly.education.core.server"})
@EnableFeignClients(basePackages = {"com.education.core.server.service.external"})
@EnableSession // 启动分布式 session 配置
@Slf4j
public class CoreServer {
public static void main(String[] args) {
SpringApplication.run(CoreServer.class, args);
}
@Value("${server.port}")
private String port;
@PostConstruct
public void finishInit(){
log.info("Start {} with port:{}",CoreServer.class.getSimpleName(),port);
}
}
其中作为中转服务调用的文件如:

其中
@FeignClient(
value="${application.service.api.system.name}",
url="${application.service.api.system.url}")
的信息在application.yaml中:

在本服务调用另一个服务的方法如:

浙公网安备 33010602011771号