Docker---(5) Docker Deployment Springboot Web Project __web

Source: Internet
Author: User

The Springboot project is a simple thing to publish to the server, but there are some potholes that need to be noticed in the Tomcat container that is posted to the Docker boot on the server.

Here's a complete introduction: Publish the Springboot Web project to the Tomcat container that is launched in Docker.

Spring Project Publishing, refer to: Docker---(3) Docker Publish Spring Web project

Springboot Introduction, please refer to: springboot--starting from 0 to learn Springboot

Docker to get started, please refer to: Docker---Learn from zero docker

1.pom.xml

Change the package mode to war package

[Java] view plain copy <packaging>war</packaging> remove springboot built-in tomcat, add Servlet-api

[Java]  View Plain  copy <dependency>       <groupId> org.springframework.boot</groupid>       <artifactId> spring-boot-starter-web</artifactid>       <!--Remove the built-in tomcat-->        <exclusions>            <exclusion>               < groupid>org.springframework.boot</groupid>                <artifactId>spring-boot-starter-tomcat</artifactId>           </exclusion>       </ exclusions>   </dependency>   <!--add servlet-api-->   <dependency >       <groupid>org.apache.tomcat</groupid>       <artifactId> tomcat-servlet-api</artifactid>       <version>8.0.36</version>        <scope>provided</scope>   </dependency>    Add Project Access path to build[Java]View Plain Copy <finalName>tweb</finalName>

(When I first published, I read 30 articles, did not mention this, published more than 20 times did not succeed)

[Java] view plain copy <build> <!--packaged Project Access name--> <finalname>tweb</finalname>       ;               <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </b Uild> 2. Customize a Servletinitializer class that inherits Springbootservletinitializer to start the context

(and start class directory siblings)

[Java]   View plain  copy package com.jd;      import  org.springframework.boot.autoconfigure.enableautoconfiguration;   import  org.springframework.boot.builder.springapplicationbuilder;   import  org.springframework.boot.web.support.springbootservletinitializer;   import  org.springframework.context.annotation.componentscan;   import  org.springframework.context.annotation.configuration;     /**   * Date  2018/1/30   * description: Start spring's context    */     

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.