//使用eureka实现服务发现功能
Feign是声明式web服务客户端。
(1)启动eureka服务器
@SpringBootApplication
@EnableEurekaServer
public class ApplicationEurekaServer {
public static void main(String[] args) {
new SpringApplicationBuilder(ApplicationEurekaServer.class)
.web(true)
.run(args);
}
}
(2)eureka相关配置
eureka:
instance:
hostname: localhost
client:
registerWithEureka: false
fetchRegistry: false
serverUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
(3)定义eureka服务
@SpringBootApplication
@RestController
@EnableDiscoveryClient
public class HelloAppplication {
@Autowired
DiscoveryClient client;
public static void main(String[] args) {
SpringApplication.run(HelloApplication.class, args);
}
@RequestMapping("/")
public void hello() {
ServiceInstance instance = client.getLocalServiceInstance();
return "hello world: from " + instance.getServiceId() + ":" + ins
Eureka结合Feign使用案例
最新推荐文章于 2024-04-11 13:09:58 发布