I'd like to know which port tomcat uses for my Spring app.
To get the address I use:
InetAddress inetAddress = InetAddress.getLocalHost();
String host = inetAddress.getHostAddress()
But there isn't port info anywhere inside. I don't have application.properties with server.host or server.port specified inside, so environment.getProperty("server.port") returns null.
I've also tried this solution:
@Inject
private ServerProperties serverProperties;
...
serverProperties.getPort()
but it also returns null
I read here that I should use Socket#getLocalPort() but I don't know how to get Socket and a new instance returns default value: -1
There's also a way to do it while capturing request:
ServletRequest.getLocalAddr();
ServletRequest.getLocalPort();
but in my case it's not useful.