Spring Boot is very clever. By specifying @EnableAutoConfiguration on the main class of the application, it goes through your PATH and looks at what you have (what your Maven Dependencies are). It then makes sure to include everything you may need and configures them with sensible defaults so it all works.
However, you can change all of these things. For example, to change Tomcat to use a different port and context you can go to Run > Run Configurations > Spring Boot App, select your app from the left hand side > Arguments tab, and then there’s a space to add Program arguments. The example I was following was a bit old. Google resulted in https://www.baeldung.com/spring-boot-context-path, so:
--server.port=9000 --server.context-path=/test
changed to:
--server.port=9000 --server.servlet.context-path=/test
The article shows 5 ways to change the context path and shows the priority applied to each way, as you can imagine that these settings would be duplicated and would probably be different at different times. It shouldn’t, but you know it would be! It could always be used as a fallback I suppose too.
Must remember to press the Relaunch spring boot icon to pick up changes, which in STS is a red square with a green triangle over it to the bottom right.
I next moved these properties into src/main/resources/application.properties
server.port=9000 server.servlet.context-path=/test
I then added two more. ‘name’ is used in the Application.java file, and ‘type’ is used in ‘name’ in the properties file.
type=Framework
name=Spring Boot ${type}
Application.java:
@Value("${name}")
String name;
//end-point for the rest controller
@RequestMapping("/")
public String home() {
return name;
}