如何将现有项目中的log4j迁移到log4j2,我在下面附上我的pom.xml,请支持

问题描述 投票:0回答:0

为了将 log4j:1.2.17 迁移到 log4j2,我尝试了某些步骤 首先我从 spring-boot-starter 项目中排除了 log4j 相关的传递依赖, 并为 spring-boot-starter-logging 添加一个新的依赖项,我的 pom 中的当前 ${spring-boot.version} 是 2.6.3 但在这样做之后我得到一个例外说明 Caused by: org.apache.logging.log4j.LoggingException: log4j-slf4j-impl cannot be present with log4j-to-slf4j 正如这个错误所说,它们是我类路径中同一 API 的两个实现,但我可以追踪到这个 log4j-to-slf4j 的来源,所以我可以删除它,因为 log4j-slf4j 作为传递依赖来自 spring-boot-starter-logging 请在下面找到随附的 POM

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ADE</groupId>
<artifactId>ADE</artifactId>
<version>2.0.5</version>
<packaging>war</packaging>

<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>

            <artifactId>maven-war-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <webResources>
                    <resource>
                        <directory>UI</directory>
                        <targetPath>UI_${project.version}</targetPath>
                    </resource>
                    <resource>
                        <directory>config</directory>
                        <targetPath>WEB-INF/classes/config</targetPath>
                    </resource>
                    <resource>
                        <directory>WebContent/WEB-INF</directory>
                        <targetPath>WEB-INF</targetPath>
                    </resource>
                    <resource>
                        <directory>jmxLibs</directory>
                        <targetPath>WEB-INF/lib</targetPath>
                    </resource>

                </webResources>
                <warName>${artifactId}</warName>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring-boot.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20160212</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.5</version>
    </dependency>

    <!-- <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> 
        <version>1.2.17</version> </dependency> -->

    <!-- <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> 
        <version>2.20.0</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> 
        <artifactId>log4j-core</artifactId> <version>2.20.0</version> <exclusions> 
        <exclusion> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-to-slf4j</artifactId> 
        </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> 
        <artifactId>log4j-slf4j-impl</artifactId> <version>2.20.0</version> </dependency> -->

    <dependency>
        <groupId>com.opencsv</groupId>
        <artifactId>opencsv</artifactId>
        <version>4.2</version>
    </dependency>
    <dependency>
        <groupId>xerces</groupId>
        <artifactId>xercesImpl</artifactId>
        <version>2.11.0</version>
    </dependency>
    <dependency>
        <groupId>org.jsoup</groupId>
        <artifactId>jsoup</artifactId>
        <version>1.8.3</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.7</version>
    </dependency>
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.11</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>

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

    <!-- <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-to-slf4j</artifactId> 
        <version>2.19.0</version> <exclusions> <exclusion> <groupId>org.apache.logging.log4j</groupId> 
        <artifactId>log4j-api</artifactId> </exclusion> </exclusions> </dependency> 
        <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> 
        <version>2.19.0</version> </dependency> -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-quartz</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.xerial</groupId>
        <artifactId>sqlite-jdbc</artifactId>
    </dependency>

    <dependency>
        <groupId>org.yaml</groupId>
        <artifactId>snakeyaml</artifactId>
        <version>1.26</version>
    </dependency>

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

    <!-- https://mvnrepository.com/artifact/com.jcraft/jsch -->
    <dependency>
        <groupId>com.jcraft</groupId>
        <artifactId>jsch</artifactId>
        <version>0.1.55</version>
    </dependency>

    <dependency>
        <groupId>com.agnity</groupId>
        <artifactId>ase</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/jmxLibs/ase.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>com.agnity</groupId>
        <artifactId>jmxide</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/jmxLibs/jmxide.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>com.agnity</groupId>
        <artifactId>jmxari</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/jmxLibs/jmxri.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>com.agnity</groupId>
        <artifactId>jmxremote</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/jmxLibs/jmxremote.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>com.agnity</groupId>
        <artifactId>jmxremote_optional</artifactId>
        <version>1.0</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/jmxLibs/jmxremote_optional.jar</systemPath>
    </dependency>


</dependencies>

<properties>
    <spring-boot.version>2.6.3</spring-boot.version>
</properties>
下面还有 log42.xml
<?xml version="1.0" encoding="UTF-8"?>
%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p - %m%n

我正在寻求一些紧急帮助

java spring-boot logging log4j log4j2
© www.soinside.com 2019 - 2024. All rights reserved.