Project background

The project needs to deploy the WAR package to Tomat and then stomp a lot of holes in the network, note that

Tomcat_zhuyu19911016520-CSDN blog _Springboot War package is deployed to Tomcat

Win10 environment Tomcat installation and environment variables configuration tutorial _LL_Leung’s blog -CSDN blog _tomcat windows10

1. Configure the Tomcat environment in Windows

  • Configuring the JDK Environment
  • CATALINA_HOME: Path Full path for storing the Tomcat folder. D: \ apache tomcat — 8.5.73
  • After path: %CATALINA_HOME%\lib, %CATALINA_HOME%\bin

2. Package in Spring Boot

public class Application extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication app=new SpringApplication(Application.class); ApplicationContext context = app.run(args); String serverPort=context.getEnvironment().getProperty("server.port"); log.info("start at http:localhost:"+serverPort); } @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(Application.class); }}Copy the code

3. The pom

<packaging>war</packaging>
Copy the code
<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-undertow</artifactId> <scope>provided</scope> </dependency>Copy the code
< the dependency > < groupId > javax.mail. Servlet < / groupId > < artifactId > javax.mail. The servlet API - < / artifactId > < version > 3.1.0 < / version > <scope>provided</scope> </dependency>Copy the code
<build>
    <finalName>SE</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
</build>
Copy the code

Note: If you want to use external Tomcat, you need to exclude the original Tomcat. If you want to use it in normal projects, you need to add spring-boot-starter-undertow or Tomcat, where provided means that it exists in the development environment and is not included in the package. Javax. servlet-API will not be packaged without reference; SE is used to determine the name of the package; War is packaged as a WAR package, which is jar by default

3. Configure it in Tomcat

  • If the code, will the conf/logging. The properties to Java. Util. Logging. ConsoleHandler. Encoding = GBK
  • In the server. The XML configuration
<Service name="testWar">  
     <Connector port="8088"    maxHttpHeaderSize="8192"  maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="true" redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true"  URIEncoding="utf-8"/>   
     <Engine name="hnswzy" defaultHost="localhost">
     <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
     <Host name="localhost" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> 
         <Context path="" reloadable="true" docBase="F:\project\crash\SEquipment\SE_Video_DATA\target\SE">
         </Context>
     </Host>
     </Engine>
     </Service>
Copy the code

Where docBase=”F: project\crash\SEquipment\SE_Video_DATA\target\SE” is the absolute path to the package (at F: project\crash\SEquipment\SE_Video_DATA\target) \ se.war exists this file) opens both services

  • Or add it to the host tag of the original service
<Context path="" reloadable="true" docBase="F:\project\crash\SEquipment\SE_Video_DATA\target\SE">
         </Context>
Copy the code