spring-boot Access, with and without the project name analysis

As we all know, springboot very convenient, can simplify the project opening step to speed up the development progress.

Many beginners may have encountered such a problem, in the past springMvc project, the big guys are playing war in the running tomcat, subconsciously visit ip: port / projectName / url, request;

The springboot not only provides a container labeled as war on deployment, there is another way. Direct execution of main function to start a built-in server to process the request, this time to access the default is not necessary to add the project name, the default context-path is "/" after the name of the project will be reported together with 404 oh.

public static void main(String[] args) {
SpringApplication.run(MainTest.class, args);
logger.info("test started successfully!");
}

In a single project, not so when the modules are distributed, it is convenient to do so. But in order to follow the habits and good transition, can be handled by adding configuration:

springboot 1.x versions adding configure; server.context-path = / projectName

adding configure springboot 2.x version; server.servlet.context-path = / projectName

After plus, you can request access in accordance with the original way, it is not very easy to use them.

Guess you like

Origin www.cnblogs.com/justtodo/p/11039330.html