当client向server注册时,它会提供一些元数据,例如主机和端口,URL,主页等。Eureka server 从每个client实例接收心跳消息。 如果心跳超时,则通常将该实例从注册server中删除。
通过注解@EnableEurekaClient 表明自己是一个eurekaclient.
@SpringBootApplication @EnableEurekaClient @RestController public class ServiceHiApplication { public static void main(String[] args) { SpringApplication.run(ServiceHiApplication.class, args); } @Value("${server.port}") String port; @RequestMapping("/hi") public String home(@RequestParam String name) { return "hi "+name+",i am from port:" +port; } }
#连接注册中心地址 eureka.client.serviceUrl.defaultZone = http://localhost:8761/eureka/ server.port=8762 spring.application.name=service-hi