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