Home > other >  How to find port number of a Spring Boot app?
How to find port number of a Spring Boot app?

Time:12-12

How do I find the port number of my SpringBoot app so I can call it? I already tried setting -Dserver.port=8080 and--server.port=8080 in VM arguments and in src/main/resources/application.properties.

If I try to go to localhost:8080 Chrome says refused to connect. I simply want to be able to connect to my App don't know why Spring Boot made finding which port is being used so challenging.

I'm using Eclipse and the app appears to be running properly from the logs.

This simply printed 0:

@Value("${local.server.port}")
int port;

I've tried these answers none work: Spring Boot - How to get the running port Spring boot - how to get running port and ip address How to configure port for a Spring Boot application How to configure port for a Spring Boot application

CodePudding user response:

localhost:<your port> may not respond at all. Make sure you're hitting an endpoint you know is availible like localhost:8080/info.

As @BrianC mentioned make sure your app is actually a web server.

CodePudding user response:

in your springboot main method use below code to detect port of your application

  Environment environment =app.run(args).getEnvironment();
    System.out.println(environment.getProprty("server.port");

this will tell you actual port where your aplication running .

  • Related