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:
this time the project has not yet webapp directory can also be created manually IDEA automatically generated
double-click the red text and then click OK in the pop-up box, you can:
Click the plus sign to generate xml file
generation path: project name \ src \ main \ webapp \ WEB -INF \ web.xml
this directory there:
Then configure the external Servlet container
here to Tomcat for example:
selecting Local local path to add the Tomcat
configuration of Tomcat local path:
Click the plus sign to add Artifact
choose war package:
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
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);
}
}