Category: Spring boot (16)
Directory (?) [+]
Original address: http://m.blog.csdn.NET/article/details?id=52515226
Publish the Spring-boot project to the Tomcat container in the same way as usual Web projects next , modify the packaging form
Set <packaging>war</packaging> II in Pom.xml , remove embedded tomcat plugin
Find the Spring-boot-starter-web dependency node in Pom.xml and add the following code to the
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId> Spring-boot-starter-web</artifactid>
<!--remove embedded Tomcat plugin-->
<exclusions>
< exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId> spring-boot-starter-tomcat</artifactid>
</exclusion>
</exclusions>
</ Dependency>
iii. adding Servlet-api dependencies
All of the following two ways can be selected, either
<dependency>
<groupId>javax.servlet</groupId>
<artifactid>javax.servlet-api </artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId> tomcat-servlet-api</artifactid>
<version>8.0.36</version>
<scope>provided</ Scope>
</dependency>
Iv. Modify the startup class and override the initialization method
The way we normally start with the main method, there is a startup class for the app, and the code is as follows:
@SpringBootApplication public
class Application {public
static void Main (string[] args) {
Springapplication.run (Application.class, args);
}
We need a configuration like Web.xml to start the spring context, add a springbootstartapplication class at the sibling of the application class with the following code:
/**
* Modifies the startup class, inherits Springbootservletinitializer, and overrides the Configure method/public
class Springbootstartapplication Extends Springbootservletinitializer {
@Override
protected Springapplicationbuilder Configure ( Springapplicationbuilder builder) {
//note here to point to the application start class return builder.sources that was previously performed with the Main method
( Application.class);
}
Five, packaged deployment
In the project root (that is, the directory containing the Pom.xml), enter at the command line:
MVN Clean Package can wait for the package to complete, the [INFO] Build success is the package success.
The war package under the target directory is then placed under Tomcat's WebApps directory to launch Tomcat to automatically decompress the deployment.
Finally, enter in the browser
http://localhost:[Port number/packing project name]/
Publish Successful