springboot获取当前服务ip_如何在Spring Boot中获取本地服务器主机和端口?

  • Post author:
  • Post category:其他


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 application is listening on, i.e. localhost:8080 (or 127.x.y.z:8080). Following the Spring Boot documentation, I use the server.address and server.port properties:

@Controller

public class MyController {

@Value(“${server.address}”)

private String serverAddress;

@Value(“${server.port}”)

private String serverPort;

//…

}

When starting up the application with mvn spring-boot:run, I get the following exception:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘myController’: Injection of autowired dependencies failed; nested exception is

org.springframework.beans.factory.BeanCreat



版权声明:本文为weixin_39606048原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。