I\'m starting up a Spring Boot application with mvn spring-boot:run
.
One of my @Controller
s needs information about the host and port the a
To get the port number in your code you can use the following:
@Autowired
Environment environment;
@GetMapping("/test")
String testConnection(){
return "Your server is up and running at port: "+environment.getProperty("local.server.port");
}
To understand the Environment property you can go through this Spring boot Environment