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.BeanCreationException: Could not autowire field: ... String ... serverAddress; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'server.address' in string value "${server.address}"
Both server.address and server.port cannot be autowired.
How can I find out the (local) host/address/NIC and port that a Spring Boot application is binding on?
application.properties? - Joao Evangelistaserver.porthas a default and therefore will evaluate to something, butserver.addressdo not have, so that might be a problem - sodikInetAddressclass to get the local ip-address, for the port you can use${server.port:8080}is you are using tomcat (this trick would also work for theserver.addressof course. Just wondering why do you need this informaion, i.e what is your usecase. - M. Deinumdef hostname(): String = InetAddress.getLocalHost.getHostName. Oozie REST could then call my REST service to provide updates - medge