Is the application.properties located at the right location? Description from Spring.io:

SpringApplication will load properties from application.properties files in the following locations and add them to the Spring Environment:

  1. A /config subdirectory of the current directory.
  2. The current directory
  3. A classpath /config package
  4. The classpath root

The list is ordered by precedence (properties defined in locations higher in the list override those defined in lower locations).

Use java -jar -Dserver.port=8090 jarfilename.jar to set the port from command line.

Hint, from Spring.io: If you want to use the short term -Dport=8090, you can use server.port=${port:8080} in your application property file.

Answer from iBiber on Stack Overflow
🌐
GitHub
github.com › spring-cloud › spring-cloud-config › issues › 1396
server.port property is not worked when combing Spring Cloud Config with other Spring projects. · Issue #1396 · spring-cloud/spring-cloud-config
May 24, 2019 - server.port property is not worked when combing Spring Cloud Config with other Spring projects.#1396 · Copy link · 5teven-tian · opened · on May 24, 2019 · Issue body actions · Bug report · As title . Following is its reproduce step: set server: port: 8202 in application.yml · together with below dependencies , tomcat start at port 8082 org.springframework.cloud spring-cloud-starter-config 2.1.0.RELEASE · <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <version> 2.1.0.RELEASE</version> </dependency> I have tried to config server port programmatically when starting applications, or run with -Dserver.port=8202.
Author   spring-cloud
Discussions

Server port not resolved properly
Using value server.port=8081 in environment variables is not resolved properly. While you don't normally use dots in env variables, we use that format in SCDF with ProcessBuilder. This used to work with boot 1.5 but now breaks with 2.x snapshots. spring-attic/spring-cloud-deployer-local#62 More on github.com
🌐 github.com
1
July 17, 2017
java - @Value("${local.server.port}") not working in Spring boot 1.5 - Stack Overflow
I am upgrading Spring Boot from 1.3 to 1.5. For upgrading to 1.5 I have replaced @SpringApplicationConfiguration(classes = TestConfig.class) @WebIntegrationTest with @SpringBootTest(classes = More on stackoverflow.com
🌐 stackoverflow.com
java - How to configure port for a Spring Boot application - Stack Overflow
Bring the best of human thought ... at your work. Explore Stack Internal ... How do I configure the TCP/IP port listened on by a Spring Boot application, so it does not use the default port of 8080. ... If someone interested, here is shown how to have multiple ports - stackoverflow.com/questions/36357135/… ... if you use "yml" file for configuration then you can use this server: port: 8081 ... More on stackoverflow.com
🌐 stackoverflow.com
${local.server.port} not resolved in application.properties
I can set this in src/test/resources/config/application.properties to get a free random port: server.port=0 Also I can get the actual random port injected into my test case like this: @Value("... More on github.com
🌐 github.com
4
February 3, 2016
🌐
Baeldung
baeldung.com › home › spring › spring boot › how to change the default port in spring boot
How to Change the Default Port in Spring Boot | Baeldung
July 25, 2025 - For Spring Boot 1.x, we can similarly implement the EmbeddedServletContainerCustomizer interface. When packaging and running our application as a jar, we can set the server.port argument with the java command: ... As a final note, let’s look at the order in which these approaches are evaluated by Spring Boot.
🌐
GitHub
github.com › spring-projects › spring-boot › issues › 9770
Server port not resolved properly · Issue #9770 · spring-projects/spring-boot
July 17, 2017 - Using value server.port=8081 in environment variables is not resolved properly. While you don't normally use dots in env variables, we use that format in SCDF with ProcessBuilder. This used to work with boot 1.5 but now breaks with 2.x snapshots. spring-attic/spring-cloud-deployer-local#62
Author   spring-projects
Top answer
1 of 4
12

You have to provide a value for webEnvironment. In your case DEFINED_PORT like this

@SpringBootTest(classes = App.class, webEnvironment = WebEnvironment.DEFINED_PORT)
public class YourTest {

  @LocalServerPort           // shorthand for @Value("${local.server.port}")
  private Integer port;
  ...
}

For details see: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html#boot-features-testing-spring-boot-applications

2 of 4
4

Adding another alternate solution which I had elsewhere.

I had configured

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

and

@RunWith(SpringRunner.class)
@SpringBootTest(classes = App.class, webEnvironment = WebEnvironment.RANDOM_PORT)
public class YourTest {

  @LocalServerPort           // shorthand for @Value("${local.server.port}")
  private Integer port;
  ...
}

Thinking that was it, and still getting this error even when specifying web environment etc. My ${local.server.port} seemed to be always null.

After some time, I noticed that my Spring Boot startup message contained no notion of the port it was using, so apparently it really didn't listen to any port at all - which explained why it was null in the first place. Adding actual container implementation dependency:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
    </dependency>

Caused this to appear on my logs:

2019-02-26 18:45:47.231  INFO 12504 --- [           main] o.s.b.web.embedded.jetty.JettyWebServer  : Jetty started on port(s) 43132 (http/1.1) with context path '/'

after which local.server.port and @LocalServerPort would also work.

🌐
Spring
docs.spring.io › spring-boot › docs › 1.3.3.RELEASE › reference › html › howto-properties-and-configuration.html
69. Properties & configuration
server: port: 9000 --- spring: profiles: development server: port: 9001 --- spring: profiles: production server: port: 0 · In this example the default port is 9000, but if the Spring profile ‘development’ is active then the port is 9001, and if ‘production’ is active then it is 0. The YAML documents are merged in the order they are encountered (so later values override earlier ones). To do the same thing with properties files you can use application-${profile}.properties to specify profile-specific values. Spring Boot binds external properties from application.properties (or .yml) (and other places) into an application at runtime.
🌐
Stack Overflow
stackoverflow.com › questions › 21083170 › how-to-configure-port-for-a-spring-boot-application › 65795203
java - How to configure port for a Spring Boot application - Stack Overflow
set server.port=8080 in application properties. this configuration is in ServerProperties.class class under org.springframework.boot.autoconfigure.web.
Find elsewhere
🌐
GitHub
github.com › spring-projects › spring-boot › issues › 5077
${local.server.port} not resolved in application.properties · Issue #5077 · spring-projects/spring-boot
February 3, 2016 - I can set this in src/test/resources/config/application.properties to get a free random port: server.port=0 Also I can get the actual random port injected into my test case like this: @Value("${local.server.port}") private int port; Howe...
Author   spring-projects
🌐
HowToDoInJava
howtodoinjava.com › home › spring boot › spring boot: change default port of embedded server
Spring Boot: Change Default Port of Embedded Server
May 27, 2024 - To scan for a free port (using OS natives to prevent clashes), use ‘server.port=0‘. Now Spring boot will find any unassigned HTTP port for us.
🌐
GitHub
github.com › spring-projects › spring-boot › issues › 14877
Can't inject local.server.port into a @Configuration so it can be wired into a @Component · Issue #14877 · spring-projects/spring-boot
October 17, 2018 - @Configuration class ApolloConfig { @Bean @Profile( "!test" ) static ApolloClient.Builder prodClient( @Value( "${phdb.endpoint}" ) String graphqlEndpoint ) { return ApolloClient.builder().serverUrl( graphqlEndpoint ); } @Bean @Profile( "test" ) static ApolloClient.Builder testClient(@Value( "${local.server.port}" ) int port ) { return ApolloClient.builder(); } } ... Unexpected exception during bean creation; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'local.server.port' in value "${local.server.port}"
Author   spring-projects
🌐
Spring
docs.spring.io › spring-boot › docs › 1.3.0.RELEASE › reference › html › howto-properties-and-configuration.html
69. Properties & configuration - Spring
Spring Boot logs the configuration files that are loaded at DEBUG level and the candidates it has not found at TRACE level. See ConfigFileApplicationListener for more detail. Some people like to use (for example) --port=9000 instead of --server.port=9000 to set configuration properties on the command line.
🌐
Namastecode
namastecode.com › posts › configure-the-port-for-a-spring-boot-application
Configuring the Port for a Spring Boot Application · Namastecode
September 9, 2024 - The properties might not be available in our project if we’re using the YAML format. In this case, we can configure the port in the application.yml file: ... Another option is to assign a random port to the application. We can easily avoid port conflicts using this method. To do this, we set the server.port property to 0: ... Now, when we start the application, Spring Boot will dynamically assign an available port.
🌐
Reddit
reddit.com › r/springboot › docker: despite modifying server.port value, application is starting in 8080 only. need to know why
r/SpringBoot on Reddit: Docker: Despite modifying server.port value, application is starting in 8080 only. Need to know why
October 30, 2023 -

Hey there, I'm learning docker by incorporating Dockerfile in my project(spring boot). When i try to run the application, application is running at port 8085(i have put server.port to 8085 in my application.yml file). But when i try to run the application using docker, application is starting in port 8080. Can someone help me why it is happening in that way? and please share me instructions to achieve what i want to...

Let me know if you need code base, will share it

Also figured out that application is falling back to default configuration(see logs)

Commands I have used:

  • To build docker image: docker build -t image-name:latest

  • To run container: docker run -ip 8085:8085

Screenshots of Dockerfile , logs and application.yml

application.yml

Dockerfile

Logs
🌐
Spring
docs.spring.io › spring-boot › how-to › webserver.html
Embedded Web Servers :: Spring Boot
server: port: 8443 ssl: key-store: "classpath:keystore.jks" key-store-password: "secret" key-password: "another-secret" Using configuration such as the preceding example means the application no longer supports a plain HTTP connector at port 8080. Spring Boot does not support the configuration ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1287738 › i-deployed-a-spring-boot-app-with-tomcat-it-shows
I deployed a spring boot app with tomcat . it shows deployed successfully. But when i run the application it shows web app failed to start . Http didn't receive the pings on port 80. Unable to start web server error? How to resolve this? - Microsoft Q&A
May 19, 2023 - If you want to listen on port 80, you need to configure your application to do so. You can do this by adding the following line to your application.properties file: server.port=80 · Check if your application is running with the correct permissions.
🌐
Stack Abuse
stackabuse.com › how-to-change-port-for-spring-boot-applications
How to Change Port for Spring Boot Applications
January 19, 2022 - There are two types of properties files typically used in Spring Boot projects - application.properties and application.yml. The application.properties file follows a simple key-value format, where each line represents a new key. The application.yml file follows the YAML format. Both of these are very human-readable and straightforward and typically, when you start out with a skeleton project, the server.port is the only setting you'll have. ... Note: You can set the port to a random available port, by setting it to 0.
🌐
ADevGuide
adevguide.com › home › blog › an easy step-by-step guide to changing server port in a spring boot application [4 ways]
An Easy Step-By-Step Guide to Changing Server Port in a Spring Boot Application [4 Ways] | ADevGuide
February 10, 2026 - Set the port via environment variable (works across all methods): # Linux/Mac export SERVER_PORT=9090 java -jar myapp.jar # Windows set SERVER_PORT=9090 java -jar myapp.jar # Docker docker run -e SERVER_PORT=9090 -p 9090:9090 myapp · Spring Boot automatically maps SERVER_PORT to server.port property.
🌐
Java Development Journal
javadevjournal.com › home › spring boot › how to change the default port in spring boot
How to Change the default port in Spring Boot | Java Development Journal
March 3, 2021 - Changing the default port in Spring Boot using application.properties is the most common and flexible way. We have the option to programmatically configure your embedded servlet container. To do this, create a Spring bean which implements the WebServerFactoryCustomizer interface. @Component public class CustomizationPort implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> { @Override public void customize(ConfigurableServletWebServerFactory server) { server.setPort(9001); } }