Add context path to Spring Boot application

To add a context path to a Spring Boot application, you can use the server.context-path property in the application's application.properties file.

Here's an example of how you can set the context path in a Spring Boot application:

server.context-path=/myapp

This will set the context path of the application to "/myapp".

Alternatively, you can set the context path programmatically in your application's code by using the SpringApplication.setDefaultProperties method:

@SpringBootApplication
public class MyApplication {
  public static void main(String[] args) {
    SpringApplication app = new SpringApplication(MyApplication.class);
    app.setDefaultProperties(Collections.singletonMap("server.context-path", "/myapp"));
    app.run(args);
  }
}

This will set the context path to "/myapp" for the entire application.

Note that the context path is the base URL for the application, and is used to distinguish it from other applications that may be running on the same server. For example, if the context path is set to "/myapp", the application will be accessible at the URL "http://example.com/myapp".