Philip Rego
Philip Rego

Reputation: 648

How to find port number of a Spring Boot app?

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

Upvotes: 0

Views: 3222

Answers (3)

ishant kulshreshtha
ishant kulshreshtha

Reputation: 119

Value can be found using Spring’s Environment as it represents the environment in which the current application is running. It can also be used to find other properties in applications like profiles.

 @Autowired Environment environment; 
 String port = environment. getProperty("local.server.port");

Upvotes: -1

Philip Rego
Philip Rego

Reputation: 648

localhost:<your port> may not respond at all. Make sure you're hitting an endpoint you know is availible like localhost:8080/info. Make sure your app has completly started, it could take serveral minutes.

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

Upvotes: 1

Dhiraj Surve
Dhiraj Surve

Reputation: 392

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 .

Upvotes: 0

Related Questions