我正在使用 log4j2 通过 lombok 插件进行日志记录。但是,我的应用程序似乎没有使用 log4j2 进行日志记录,并且总是回退到 commons-logging。我尝试了多种选择,但似乎没有任何效果。任何帮助是极大的赞赏。我在 Maven 依赖项中排除了 commons-logging,因此代码选择了 log4j2,但我得到了 java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory。Maven 依赖项<dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.3.3.RELEASE</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>javax.servlet.jsp-api</artifactId> <version>2.3.1</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.8</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.11.1</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.11.1</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.4.1</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.4.1.1</version> </dependency>
1 回答
达令说
TA贡献1821条经验 获得超6个赞
我已经克隆了您的项目并看到了问题。不排除commons-logging。将您移至log4j.xml并src/main/resources(可选)将src/main/resources/log4j.xml日志路径更改为fileName="../logs/springMvcTest.log". 以下是来自的日志语句springMvcTest.log:
2019-07-28 21:14:57.516 [http-nio-84-exec-30] INFO com.test.epi.controller.HelloWorldController - Input => GET / /helloJson % {}
2019-07-28 21:14:57.518 [http-nio-84-exec-30] INFO com.test.epi.controller.HelloWorldController - Logger class: class org.apache.logging.log4j.core.Logger
让 Spring 框架使用commons-logging. 对于您的应用程序特定的日志记录,请继续使用log4j.
添加回答
举报
0/150
提交
取消