I have a Spring Webflux application with Spring Boot ver 2.3.5
How can I get a server port of running Netty container at runtime? (Not in tests)
Note: nor @Value("${server.port}")
neither @Value("${local.server.port}")
do not work if the port is not specified in the configuration.
After I looking into the spring boot library, I found that there is a ReactiveWebServerApplicationContext
. It can give you the port.
@Autowired
private ReactiveWebServerApplicationContext server;
@GetMapping
public Flux<YourObject> getSomething() {
var port = server.getWebServer().getPort());
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With