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.
Include below property in application.properties
server.port=8080
There are many other stuffs you can alter in server configuration by changing application.properties. Like session time out, address and port etc. Refer below post
ref: http://docs.spring.io/spring-boot/docs/1.4.x/reference/html/common-application-properties.html
I used few of them as below.
server.session.timeout=1
server.port = 3029
server.address= deepesh
In the application.properties
file, add this line:
server.port = 65535
where to place that fie:
24.3 Application Property Files
SpringApplication loads properties from application.properties files in the following locations and adds them to the Spring Environment:
A /config subdirectory of the current directory The current directory A classpath /config package The classpath root
The list is ordered by precedence (properties defined in locations higher in the list override those defined in lower locations).
In my case I put it in the directory where the jar
file stands.
From:
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config-application-property-files
There are two main ways to change the port in the Embedded Tomcat in a Spring Boot Application.
Modify application.properties
First you can try the application.properties file in the /resources folder:
server.port = 8090
Modify a VM option
The second way, if you want to avoid modifying any files and checking in something that you only need on your local, you can use a vm arg:
Go to Run -> Edit Configurations -> VM options
-Dserver.port=8090
Additionally, if you need more information you can view the following blog post here: Changing the port on a Spring Boot Application
also, you can configure port programmatically
@Configuration
public class ServletConfig {
@Bean
public EmbeddedServletContainerCustomizer containerCustomizer() {
return (container -> {
container.setPort(8012);
});
}
}
You can set port in java code:
HashMap<String, Object> props = new HashMap<>();
props.put("server.port", 9999);
new SpringApplicationBuilder()
.sources(SampleController.class)
.properties(props)
.run(args);
Or in application.yml:
server:
port: 9999
Or in application.properties:
server.port=9999
Or as a command line parameter:
-Dserver.port=9999