java - Spring MVC + Log4j2 在未识别的类路径位置中定义 log4j2.properties 文件

标签 java spring-mvc log4j log4j2

我正在尝试使用 log4j2 日志记录功能配置 Spring(非启动)MVC 项目。目前,我已将所有 *.properties 文件放置在类路径之外的位置。我对此配置使用了 @PropertySource 注释。我收到以下消息

ERROR StatusLogger No Log4j 2 configuration file found.
Using default configuration (logging only errors to the console), or user programmatically provided configurations.
Set system property 'log4j2.debug' to show Log4j 2 internal initialization logging.
See https://logging.apache.org/log4j/2.x/manual/configuration.html for instructions on how to configure Log4j 2

关于我如何以及在哪里做错的任何线索?如果有好的引用资料可供检查,请分享。

最佳答案

将log4j2-web包添加到项目中,然后在web.xml上添加监听器:

<listener>
    <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
</listener>

您可以在此处设置配置路径:

<context-param>
    <param-name>log4jConfiguration</param-name>
    <param-value>file:///D:/conf/myLogging.xml</param-value>
</context-param>

关于java - Spring MVC + Log4j2 在未识别的类路径位置中定义 log4j2.properties 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51169829/

相关文章:

java - 不保存到 MySQL 数据库中的 Java

java - 在 URL 中附加特殊字符

java - curl 是否删除换行符?

java - spring-data-rest 没有与 spring-mvc 完全集成

java - 使用 log4j 记录不同的对象

java - 检测 Java 应用程序是否以 Windows 管理员身份运行

java - 从一点到另一点绘制拱形

security - 清理 Tomcat 访问日志条目

java - 外部系统集成最佳实践

java - 需要帮助在 Windows(Java、NetBeans)上的 Tomcat 中为 log4j 运行定制的 glass/jar