IDEA SpringBoot configuration using external Servlet Container (the Tomcat)

SpringBoot default is to use an embedded Servlet Container application executable jar labeled package
in this way has advantages and disadvantages

  • Advantages:
    simple and convenient
  • Cons:
    default does not support JSP
    optimize and customize more complex (only use Customizer ServerProperties or custom embedded Servlet container customizer to customize)

Using an external Servlet container:

First when creating project applications by way of war package packaging:
Here Insert Picture Description
this time the project has not yet webapp directory can also be created manually IDEA automatically generated
Here Insert Picture Description
double-click the red text and then click OK in the pop-up box, you can:
Here Insert Picture Description
Click the plus sign to generate xml file
generation path: project name \ src \ main \ webapp \ WEB -INF \ web.xml
Here Insert Picture Description
this directory there:
Here Insert Picture Description


Then configure the external Servlet container
here to Tomcat for example:
selecting Local local path to add the Tomcat
Here Insert Picture Description
configuration of Tomcat local path:
Here Insert Picture Description
Click the plus sign to add Artifact
Here Insert Picture Description
choose war package:
Here Insert Picture Description
then apply then ok to save
Once configured, click on the upper right corner of the IDEA run button to start the external Servlet container
Here Insert Picture Description


To create a manual three points should be noted:

  • 1, the project created a war project
  • 2, range of embedded Tomcat is private
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
</dependency>
  • 3, must have a startup class
    class must inherit SpringBootServletInitializer name can be named
public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        // 传入应用的主程序
        return application.sources(SpringbootWebjarApplication.class);
    }
}

Published 174 original articles · won praise 5 · Views 240,000 +

Guess you like

Origin blog.csdn.net/Piconjo/article/details/104975975