SpringBoot 2.3.1 implements war mode packaging operation and log4j2 to achieve log output

1. First, let's talk about the realization of the war packaging method and the use of non-built-in Tomcat for writing and debugging
. When creating a new project, create the war method packaging. The steps are as shown in the two figures
Choose spring alizr methodInsert picture description hereabove, and the new project will select the packaging method as War.
If you have already established a project, you can directly modify the packaging method to war in the pom.xml file. After
Insert picture description herethe packaging method is set as shown in the figure below, you need to exclude the dependency of tomcat from spring-boot-starter-web, and Set the scope of spring-boot-starter-tomcat to provided. Provide only needs to be in the compile and test phases. Similarly, provide will not be packaged in the lib directory.
At this point, the setting has been completed. If you need non-built-in Tomcat browser debugging in idea, you can add Tomcat Server server in the debugging configuration
Insert picture description hereand then exclude tomcat from the spring-boot-starter-web dependency in pom.xml

       <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>

Second, SpringBoot 2.3.1 uses log4j2 to achieve log output
1. Since springboot2.X does not use log4j2 for log output by default, first open
Insert picture description hereand find spring-boot-starter-logging in the dependency map and then right-click to exclude it. The effect excluded here is in pom.xml

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>spring-boot-starter-logging</artifactId>
                    <groupId>org.springframework.boot</groupId>
                </exclusion>
            </exclusions>
        </dependency>

The above dependency exclusion is just an example, the actual system will exclude all dependencies that use the default log.
2. After excluding the default, introduce spring-boot-starter-log4j2 into pom.xml, and then put the configuration file of log4j2 in the resource folder

   <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>

Guess you like

Origin blog.csdn.net/u011930054/article/details/106858051