Spring Boot to fight the war package and use Docbase to specify the root directory for the packaged project

Source: Internet
Author: User
Tags tomcat server

There are two ways of specifying the root directory

1: Define the War package name as root directly

2: Using Docbase

For example, the author of the war package named Xibu.war, the war package is dropped into the /Users/archerlj/Library/apache-tomcat-8.5.8/webapps directory.
For ease of access, I modified the Server.xml file under the Conf file in the Tomcat installation directory:

The host node at the end of the file is added as follows:
<!---<path= ""  docBase= "Xibu"  reloadable= "false"/>
path is a virtual directory. Docbase is a real directory, can be a relative path or an absolute path, because Xibu.war is placed under WebApp, so the relative path is used directly.
Reference: Spring Boot Fight War Pack
  1. To set the package of springboot items to war
    <groupId>Com.example</groupId>  <Artifactid>Demo</Artifactid>  <version>1.0.0</version>  <Packaging>War</Packaging>
  2. Remove the inline Tomcat module, but we need to introduce it for our native testing, so the configuration is as follows
    <Dependency>          <groupId>Org.springframework.boot</groupId>          <Artifactid>Spring-boot-starter-web</Artifactid>          <Exclusions>              <exclusion>                  <groupId>Org.springframework.boot</groupId>                  <Artifactid>Spring-boot-starter-tomcat</Artifactid>              </exclusion>          </Exclusions>  </Dependency>  <Dependency>          <groupId>Org.springframework.boot</groupId>          <Artifactid>Spring-boot-starter-tomcat</Artifactid>          <Scope>Provided</Scope>  </Dependency>
  3. Add Tomcat-servelt-api Dependency
    <Dependency>        <groupId>Org.apache.tomcat</groupId>        <Artifactid>Tomcat-servlet-api</Artifactid>        <!--Follow server tomcat version here -      <version>7.0.42</version>        <Scope>Provided</Scope>  </Dependency>
  4. Modify the Ingress method to inherit a Springbootservletinitializer class, and override the Configure method
    Package com.example;    Import org.springframework.boot.SpringApplication;  Import org.springframework.boot.autoconfigure.SpringBootApplication;  Import Org.springframework.boot.builder.SpringApplicationBuilder;  Import Org.springframework.boot.web.support.SpringBootServletInitializer;  Import org.springframework.cache.annotation.EnableCaching;    @SpringBootApplication  @EnableCaching Public  class Springdatajpaexampleapplication extends Springbootservletinitializer {        @Override      protected Springapplicationbuilder Configure ( Springapplicationbuilder application) {          return application.sources (Springdatajpaexampleapplication.class);      } Public        static void Main (string[] args) {          Springapplication.run (Springdatajpaexampleapplication.class, args);      }  }
  5. Add the war plug-in, with the name of the war package that you customize after packaging
    <Build>        <Finalname>Springboot</Finalname>        <!--Packaged Items MVN Clean package -            <plugin>                <groupId>Org.springframework.boot</groupId>                <Artifactid>Spring-boot-maven-plugin</Artifactid>                 <Configuration>                        <Warsourceexcludes>src/main/resources/**</Warsourceexcludes>                        <Warname>Springboot</Warname>                  </Configuration>            </plugin></Build>

    The introduction of this plugin is to avoid MAVEN packaging when we default to a version number of the war package name, because after we deployed to Tomcat, when accessing the project, we need to use the name of the war package

    6. Deploying to the Tomcat server

    In most cases, there is no configuration Server.servlet.context-path when the project is being developed.

    There are two ways to do this: 1. Directly packaged as Root.war

    2. Change Docbase

    Reference: Springboot War package deployed to Tomcat

    About configuration issues with Tomcat virtual host (Appbase,docbase)

    For example, the author of the war package named Xibu.war, the war package is dropped into the /Users/archerlj/Library/apache-tomcat-8.5.8/webapps directory.
    For ease of access, I modified the Server.xml file under the Conf file in the Tomcat installation directory:

    在该文件最后的Host节点添加如下:            <!-- path留空代表访问域名后面不需要带项目的名称 -->            <Context path="" docBase="xibu" reloadable="false" />path是虚拟目录。docBase是真实目录,可以是相对路径或者绝对路径,这里因为xibu.war放在webapp下面,所以直接用了相对路径。

    This allows http://localhost:8080 you to access your project directly through access after starting Tomcat.

    OK, the CD to Tomcat in the bin directory to sudo sh startup.sh start Tomcat, this time access will be http://localhost:8080 able to access the deployed project (I modified the port: 8081)

Spring Boot to fight the war package and use Docbase to specify the root directory for the packaged project

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.