0 votes
1 view
in Java by (830 points)
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.

1 Answer

0 votes
by (13.2k points)

There are many ways to change the default port which are given as follows:

   

1.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);

Note:  Using the HashMap will work only if no port is set in applications.properties or .yml.

2. In application.yml:

 server: port: 9999

    Or in application.properties:

 server.port=9999

3. As a command line parameter:

-Dserver.port=999

...