How to get local server host and port in Spring Boot?

后端 未结 9 1228
野性不改
野性不改 2020-12-09 02:27

I\'m starting up a Spring Boot application with mvn spring-boot:run.

One of my @Controllers needs information about the host and port the a

9条回答
  •  臣服心动
    2020-12-09 03:20

    You can get hostname from spring cloud property in spring-cloud-commons-2.1.0.RC2.jar

    environment.getProperty("spring.cloud.client.ip-address");
    environment.getProperty("spring.cloud.client.hostname");
    

    spring.factories of spring-cloud-commons-2.1.0.RC2.jar

    org.springframework.boot.env.EnvironmentPostProcessor=\
    org.springframework.cloud.client.HostInfoEnvironmentPostProcessor
    

提交回复
热议问题