我设置了一个Eureka实例,然后 Build 了一个向Eureka注册的服务 .
尤里卡:
appliation.properties
spring.application.name=registry
server.port=8761
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
主要课程:
@SpringBootApplication
@EnableEurekaServer
public class RegistryApplication {
public static void main(String[] args) {
SpringApplication.run(RegistryApplication.class, args);
}
}
服务:
application.properties:
spring.application.name=example-service
server.port=1111
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
主要课程:
@SpringBootApplication
@EnableDiscoveryClient
@RestController
public class AppServiceApplication {
public static void main(String[] args) {
SpringApplication.run(AppServiceApplication.class, args);
}
@RequestMapping("/")
public String sayHi() {
return "Hi";
}
}
现在,eureka和服务都在启动,服务按照预期在eureka注册 . 然而,它注册了一个相当奇怪的主机名,我无法弄清楚究竟发生了什么或为什么会发生这种情况 . 这是显示奇怪主机名的尤里卡仪表板的屏幕截图:
我在笔记本电脑上尝试了相同的设置,主机名只是'localhost'正如预期的那样 .
有人对此有解释吗?提前谢谢你的答案!
编辑:我正在使用Spring Boot版本2.0.5.RELEASE