Springboot Creating a war package deployed on external Tomcat

Source: Internet
Author: User

Today I want to share with you how do I use Springboot to create a war package that can be deployed in an external tomcat? The internet is a lot of talk, but I still want to record:

Springboot official documentation is already clear (85.1 Create a deployable war File)

1, the main class inherits Springbootservletinitializer and overrides its configure Method.

 @SpringBootApplication 
public class application extends  springbootservletinitializer {    
    @Override
    Protected springapplicationbuilder configure (springapplicationbuilder application)  {       
        Return application.sources ( application.class);
    }    
    public static void  main (string[] args)  throws exception {
         springapplication.run (application.class, args);
    }
}

2, Modify your build configuration so that your project generates a war file instead of a jar file. If you use Maven and use spring-boot-starter-parent This class, you only need to modify pom.xml   packaging is a war. (students unfamiliar with Maven can learn about maven First)

<packaging>war</packaging>

If you use Gradle, you need to modify the build.gradle App war plugin

Apply Plugin: ' War '

3. The final step in the process is to ensure that the embedded servlet container does not interfere with the servlet container that will deploy the war File. To do this, you need to tag the provided inline servlet container dependency as Provided.

MAVEN Configuration

<dependencies> <!--...--> <dependency> <groupid>org.springframework.boot</groupid&        Gt <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </depende Ncy> <!--...--></dependencies>

Gradle Configuration

Dependencies {//... providedruntime ' Org.springframework.boot:spring-boot-starter-tomcat '//...}


Springboot Creating a war package deployed on external Tomcat

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.