springboot is packaged as war and deployed to tomcat container

Keywords: Programming Tomcat Spring Maven xml

Step 1: Modify pom.xml to increase <packaging>war</packaging>

Step 2: Remove the tomcat component

 <!-- spring boot web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!--Remove Embedded tomcat Plug-in unit-->
		    <exclusions>
		        <exclusion>
		            <groupId>org.springframework.boot</groupId>
		            <artifactId>spring-boot-starter-tomcat</artifactId>
		        </exclusion> 
		    </exclusions>
        </dependency>

Step 3: Introduce servlet jar, tomcat-related jar

 <!--remove tomcat Plug-ins need to be introduced servlet,tomcat Dependent jar package-->
	<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>

Step 4: Be careful to change the name of the project. FinlName is the name of the project.

 <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
        <finalName>demo</finalName>
    </build>

Step 5: Modify the startup class


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;

@SpringBootApplication //spring boot start
public class StartApp extends SpringBootServletInitializer {
	
	
	 @Override
	    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
	        return builder.sources(StartApp.class);
	    }
		
	public static void main(String[] args) {
		SpringApplication.run(StartApp.class, args);
	}
}

Step 6: Package the mvn clean package into war using the maven command

Then drop war into the webapp directory and start tomcat

Note: Modify your tomcat port number, oh, the port number of the original project configuration file configuration is invalid.

Start tomcat access

 

Get it done!!!

Posted by duankr on Wed, 02 Oct 2019 09:23:57 -0700