spring-boot Feign

本文介绍了一个使用Spring Boot和Feign实现的微服务客户端示例。客户端通过Feign远程调用服务提供者接口,并展示了如何配置Feign客户端及其实现的服务调用逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@SpringBootApplication
@EnableEurekaClient
@RestController
@EnableFeignClients  //开启feign
public class DemoApplication {

	@Autowired
	HelloClient client;

	@GetMapping("/hello/{name}")
	public String hello(@PathVariable String name){

		System.out.println(name+" welcome . My is microservice provider user");
		return name+" welcome . I'm microservice provider user";
	}

	@RequestMapping("/say")
	public String hello() {
		return client.hello();
	}

	@FeignClient("provider-user")
	interface HelloClient {
		@GetMapping("/add")
		String hello();
	}

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




@RequestMapping("/add")
public String hello2() {
   return "Hello";
}
Feign接口的请求映射需与注册到eureka的服务的请求地址(/add)一致,方法名可不一致,
当请求/say,则会请求到hello2方法
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值