我正在使用Spring MVC建立一个新项目,但是我无法配置Log4j2, 我遇到了许多人寻求帮助的错误。
错误StatusLogger找不到Log4j 2配置文件。使用默认配置...
工具和库:
...
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j-impl -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.11.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-jcl -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<version>2.11.2</version>
</dependency>
...
/src/com/mypackage/myproject/resorces/
where I tried to put a log4j2-test.xml file and/or a log4j2.properties, none of them worked
... / org.eclipse.wst.server.core / tmp0 / wtpwebapps / MonitorManagement / WEB-INF / classes / com / mypackage / myproject / resources
我可以找到这两种资源。
即使实际部署了资源,log4j2如何也无法找到它们?
编辑:它可以将资源直接放在src文件夹下,这是一个好方法吗?
预先感谢
答案 0 :(得分:0)
Log4j在类路径的根文件夹中查找。
在IDE中,您可以将log4j2.xml
文件放在/src
下,并且(可能)放在/resources
下。