问题描述
根据要求和安全目的,我正在更新 Struts 项目.之前 Struts 版本是 2.3.24,现在我更新到 2.5.12.我已经下载了 Struts 所需的所有 jar 文件并应用于项目,但出现以下错误
As per the requirement and for security purpose I am updating Struts project. Before the Struts version is 2.3.24 and now I am updating it to 2.5.12. I have downloaded all the required jar files of Struts and applied to project but I am getting the below error
ERROR StatusLogger 未找到 log4j2 配置文件.使用默认配置:仅将错误记录到控制台.设置系统属性'org.apache.logging.log4j.simplelog.StatusLogger.level' 到 TRACE显示 Log4j2 内部初始化日志记录.
但我没有在我的项目中使用任何记录器.我已经添加了所有的依赖 jar 文件,我没有使用 Maven,而是在 lib 文件夹中添加了相关的库.请提出任何建议.
But I am not using any logger in my project. I have added all the dependency jar files and I am not using Maven, but added related libraries in lib folder. Any suggestions please.
推荐答案
Struts 框架正在使用日志框架 log4j 第二版.
Struts framework is using a logging framework log4j second version.
请注意,该框架现在使用 Log4j2 作为主要日志记录层,现有的旧日志记录层已弃用,很快将被删除.Log4j2 支持多种不同的日志实现,请查看文档了解更多详情.
文件 log4j2.xml
是引导日志框架所必需的.但是它在类路径中丢失了.Struts 框架中也没有.
The file log4j2.xml
is required to bootstrap the logging framework. But it's missing from the classpath. It's also missing from the Struts framework.
您应该找到一些 log4j2.xml
,即来自 struts-showcase 应用程序或阅读本教程中的第 4 步 如何创建 Struts 2 Web 应用程序
You should find some log4j2.xml
, i.e. from the struts-showcase application or read a step 4 in this tutorial How To Create A Struts 2 Web Application
为了了解幕后发生的事情,本教程的示例应用程序使用 log4j2.您需要将 log4j2 的依赖节点添加到 pom:
pom.xml log4j 依赖节点
pom.xml log4j dependency node
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.8.2</version>
</dependency>
同时使用 log4j-core 和 log4j-api 允许使用最新版本的 Log4j2,而不会与框架提供的版本发生冲突.在 src/main/resources 文件夹中设置 log4j2.xml 配置,其中包含以下内容
Using both log4j-core and log4j-api allows to use the latest version of Log4j2 without a clash with version provided by the framework. Setup a log4j2.xml configuration in the src/main/resources folder which contains the following
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="com.opensymphony.xwork2" level="debug"/>
<Logger name="org.apache.struts2" level="debug"/>
<Root level="warn">
<AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
</Configuration>
注意上面的 log4j2 配置将控制台指定为日志目标.
Note the above log4j2 configuration specifies the console as the log target.
这篇关于错误 StatusLogger 未找到 log4j2 配置文件.在更新 Struts 2.5.12 版本时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!