org.springframework.boot
spring-boot-starter-test
test
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin
pom文件中要引入eureka依赖和feign依赖
2、在启动类中添加@EnableFeignClients 和 @EnableEurekaClient开启spring cloud feign功能:
@EnableFeignClients
@EnableEurekaClient
@SpringBootApplication
public class EurekaDomeCleanApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaDomeCleanApplication.class, args);
}
3、application.yml 配置:
server:
port: 7777
eureka:
client:
register-with-eureka: false
serviceUrl:
defaultZone: http://localhost:1111/eureka
注意这里的配置没有feign特有的配置
4、创建接口:
@FeignClient(“test-service”)
public interface FeignService {
@RequestMapping(“/hello”)
String hello() ;
}
注意:这里的服务名不区分大小写,所以使用test-service和TEST-SERVICE都是可以的,在BRIXTON.SR5版本中,原有的serviceis属性已经被废弃,若要写属性名,可以使用name或者value
5、使用接口调用服务:
@Autowired
private FeignService fs;
架构学习资料
![准备两个月,面试五分钟,Java中高级岗面试为何越来越难?](https://upload-images.jianshu.io/upload_images/24616006-f743953ee4032b76?imageMogr2/auto-or 需要zi料+ 绿色徽【vip1024b】
ient/strip%7CimageView2/2/w/1240)
由于篇幅限制小编,pdf文档的详解资料太全面,细节内容实在太多啦,所以只把部分知识点截图出来粗略的介绍,每个小节点里面都有更细化的内容!
ageView2/2/w/1240)
[外链图片转存中…(img-uJ5u8lxd-1710367254661)]
[外链图片转存中…(img-SiKtc1pi-1710367254661)]
由于篇幅限制小编,pdf文档的详解资料太全面,细节内容实在太多啦,所以只把部分知识点截图出来粗略的介绍,每个小节点里面都有更细化的内容!