Spring Boot playing war package

Copyright: please indicate the source https://blog.csdn.net/baidu_25104885/article/details/90261161

First, modify pom.xml

Adding provided dependent on spring-boot-starter-tomcat (depending on compile-time)

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <scope>provided</scope>
    </dependency>

Add maven-war-plugin plugin
finalName settings war package called artifactId

<build>
   
    <finalName>${project.artifactId}</finalName>
    
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-war-plugin</artifactId>
          <configuration>
            <failOnMissingWebXml>false</failOnMissingWebXml>
          </configuration>
        </plugin>
        ...

Add packaging label

  <groupId>com.lahhass</groupId>
  <artifactId>seckill_idea</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

Second, modify the startup class

Inheritance SpringBootServletInitializer, rewrite configure method

@SpringBootApplication
public class MainApplication extends SpringBootServletInitializer{

    public static void main(String[] args)throws Exception {
        SpringApplication.run(MainApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(MainApplication.class);
    }

}

Third, playing war package

After cmd into the project directory or IDEA Terminal enter: mvn clean package
after package will generate a successful war package in the target directory project

Fourth, run on tomcat

The war package into the webapps directory of tomcat
start tomcat
via http in the browser: 8080 / war package name / xxx open the project web page (this does not jump to another page because the address is incorrect): // localhost
will webapps directory generates war package of the same name WebContent folder, the folder's contents into the ROOT directory, you can remove the war package name address to access the http: // localhost: 8080 / xxx

Guess you like

Origin blog.csdn.net/baidu_25104885/article/details/90261161