Springboot Project Package Deploy external Java EE containers __java

Source: Internet
Author: User
Preface

The Springboot project is in the process of developing a built-in Tomcat,jetty container, and what happens when the project needs to be released.
Only two-step steps are required to modify the startup class, Inherit Springbootservletinitializer, and override the Configure method

/**
 * Author: Meet small star
 * email:tengxing7452@163.com
 * date:17-5-10 * time
 : a.m. 10:40
 * Describe: Program Entry 
  */
@SpringBootApplication
@EnableAutoConfiguration public
class Mainspringboot extends Springbootservletinitializer {

@Override
    protected Springapplicationbuilder Configure ( Springapplicationbuilder application) {return
        application.sources (mainspringboot.class);
    }
Modifying Pom.xml files
<!--<packaging>jar</packaging>-->  
<packaging>war</packaging>  

Tomcat plug-in Dependency pack add Lifecycle privided

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

    <dependency>
      <groupId>org.apache.tomcat.embed</groupId>
      <artifactId> tomcat-embed-jasper</artifactid>
      <scope>provided</scope>
    </dependency>
Concluding remarks

The Springbootservletinitializer class implements the Webapplicationinitializer interface, while the Webapplicationinitializer has a void OnStartup ( ServletContext var1) method

void Onstartup (ServletContext var1) throws servletexception;

Springbootservletinitializer implements this Onstartup method, mainly responsible for loading the related configuration when the container is started

public void Onstartup (ServletContext servletcontext) throws Servletexception {
        This.logger = Logfactory.getlog ( This.getclass ());
        Final Webapplicationcontext Rootappcontext = This.createrootapplicationcontext (ServletContext);
        if (Rootappcontext!= null) {
            Servletcontext.addlistener (new Contextloaderlistener (rootappcontext) {
                public void Contextinitialized (Servletcontextevent event) {
                }}
            );
        else {
            this.logger.debug ("No Contextloaderlistener registered, as Createrootapplicationcontext () did Application Context ");
        }

    }

Code

            Servletcontext.addlistener (New Contextloaderlistener (rootappcontext) {public
                void contextinitialized ( Servletcontextevent event) {
                }
            });

The Servletcontextlistener interface is implemented in the

Contextloaderlistener, so that the related configuration under Springboot Project can be loaded by AddListener ().

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.