spring boot and run the project packaged into war oa credit disk speed controllable platform to build on the steps tomcat

First, modify oa credit disk speed controllable platform to build Q848622369 packaged form

Set in the pom.xml <packaging>war</packaging>

Second, remove the plug embedded tomcat

Found in pom.xml spring-boot-starter-webdependency nodes, the following code added thereto,

  1.  
    <dependency>
  2.  
    <groupId>org.springframework.boot</groupId>
  3.  
    <artifactId>spring-boot-starter-web</artifactId>
  4.  
    <-! Remove embedded tomcat plug-ins ->
  5.  
    <exclusions>
  6.  
    <exclusion>
  7.  
    <groupId>org.springframework.boot</groupId>
  8.  
    <artifactId>spring-boot-starter-tomcat</artifactId>
  9.  
    </exclusion>
  10.  
    </exclusions>
  11.  
    </dependency>
  • =

Third, adding a dependency of servlet-api

The following two methods can, optionally one

  1.  
    <dependency>
  2.  
    <groupId>javax.servlet</groupId>
  3.  
    <artifactId>javax.servlet-api</artifactId>
  4.  
    <version>3.1.0</version>
  5.  
    <scope>provided</scope>
  6.  
    </dependency>
  • =

  1.  
    <dependency>
  2.  
    <groupId>org.apache.tomcat</groupId>
  3.  
    <artifactId>tomcat-servlet-api</artifactId>
  4.  
    <version>8.0.36</version>
  5.  
    <scope>provided</scope>
  6.  
    </dependency>
  • = Change startup class, and override the initialization method

We usually start with the way the main method, there is a App start classes, as follows:

  1.  
    @SpringBootApplication
  2.  
    public class Application {
  3.  
    public static void main(String[] args) {
  4.  
    SpringApplication.run(Application.class, args);
  5.  
    }
  6.  
    }

1

  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

We need a similar arrangement to start web.xml spring context, and add a class SpringBootStartApplication peer Application class, code is as follows:

  1.  
    /**
  2.  
    * Modify the startup class and override inherited SpringBootServletInitializer configure method
  3.  
    */
  4.  
    public class SpringBootStartApplication extends SpringBootServletInitializer {
  5.  
     
  6.  
    @Override
  7.  
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
  8.  
    // point to note here to start the Application class originally performed by main method
  9.  
    return builder.sources(Application.class);
  10.  

Fifth, the deployment package

Under the project root directory (the directory that contains the pom.xml), type in the command line: 
mvn clean packageto wait for the completion of packing, there [INFO] BUILD SUCCESSis the packaging success. 
Then the war package under the target directory into the webapps directory of tomcat, tomcat startup, automatically unzip deployment. 
Finally, enter in your browser

http://localhost:[端口号]/[打包项目名]/

Successfully posted

Guess you like

Origin www.cnblogs.com/oiweeead/p/11231971.html