在 Spring 框架下:警告:警告找不到记录器的附加程序(org.springframework.web.context.ContextLoader)

2023-12-22

我花了一整天的时间试图解决 web 应用程序中使用 log4j 时遇到的日志记录问题。无论我做什么,我都无法摆脱以下问题:

log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

需要明确的是,我已阅读 Stack Overflow 上解决此问题的所有文章。我读过 log4j 手册。我已经完成了十几个不同的教程。我尝试过属性方法和 XML 方法(分别为 log4j.properties 和 log4j.xml)。另外,我已确认正在读取 log4j.xml 文件。除了服务器在启动期间告诉我这一点之外,我还可以通过 .xml 文件影响反馈级别。所以,是的,log4j.xml 文件位于 CLASSPATH 中。

我知道我错过了一些简单而基本的东西。以下是相关文件:

LOG4J.XML(/WEB-INF):

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
    <param name="Target" value="System.out" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%-5p: %c - %m%n" />
    </layout>
</appender>

<!-- Application Loggers -->
<logger name="com.tiersoftinc.testlog">
    <level value="info" />      
</logger>

<!-- 3rdparty Loggers -->
<logger name="org.springframework.core">
    <level value="info" />      
</logger>

<logger name="org.springframework.beans">
    <level value="info" />      
</logger>

<logger name="org.springframework.context">
    <level value="info" />      
</logger>

<logger name="org.springframework.web">
    <level value="info" />      
</logger>

<!-- Root Logger -->
<root>
    <priority value="warn" />
    <appender-ref ref="console" />
</root>

</log4j:configuration>

和 WEB.XML (/WEB-INF):

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<!-- The definition of the Root Spring Container shared by all Servlets and Filters, and the applicationContext.xml file -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        /WEB-INF/spring/root-context.xml
        /WEB-INF/spring/app-context.xml         
    </param-value>      
</context-param>    

<!-- Logging listener -->
<listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>/WEB-INF/log4j.xml</param-value>
</context-param>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>      
</listener>

<!-- Processes application requests -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>           
    </init-param>       
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>appServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>  

</web-app>

和 APP-CONTEXT.XML (/WEB-INF/spring):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

<!-- Activates various annotations to be detected in bean classes -->   
<context:annotation-config />   

<!-- Scans the classpath for annotated components that will be auto-registered as Spring beans. 
For example @Controller and @Service. Make sure to set the correct base-package --> 
<context:component-scan base-package="com.tiersoftinc.gridlab3" />   

<!-- Configures the annotation-driven Spring MVC Controller programming model.  
Note that, with Spring 3.0, this tag works in Servlet MVC only! --> 
<mvc:annotation-driven />

<mvc:resources mapping="/resources/**" location="/resources/" />        

<!-- Imports datasource configuration -->   
<import resource="app-context-mongo.xml"/>

</beans>

和 APP-CONTEXT-MONGO.XML (/WEB-INF/spring):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:c="http://www.springframework.org/schema/c"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                    http://www.springframework.org/schema/tx
                    http://www.springframework.org/schema/tx/spring-tx-3.1.xsd                      
                    http://www.springframework.org/schema/context                       
                    http://www.springframework.org/schema/context/spring-context-3.1.xsd                        
                    http://www.springframework.org/schema/data/mongo                        
                    http://www.springframework.org/schema/data/mongo/spring-mongo-1.0.xsd                       
                    http://www.springframework.org/schema/util                      
                    http://www.springframework.org/schema/util/spring-util-3.1.xsd">    

<!-- Activate Spring Data MongoDB repository support -->
<mongo:repositories base-package="com.tiersoftinc.gridlab3.repository" />

<bean id="propertyPlaceholderConfigurer"   
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
    <property name="locations">  
        <list>  
            <value>/WEB-INF/spring/database.properties</value>  
        </list>  
    </property> 
</bean>  

<!-- MongoDB host -->
<mongo:mongo host="${mongo.host.name}" port="${mongo.host.port}"/> 

<!-- Template for performing MongoDB operations -->
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate"

c:mongo-ref="mongo" c:databaseName="${mongo.db.name}"/>

<!-- Service for initializing MongoDB with sample data using MongoTemplate -->
<bean id="initGridLab3Service" class="com.tiersoftinc.gridlab3.services.InitGridLab3Service" init-method="init"/>   

</beans>

最后是 ROOT-CONTEXT.XML (/WEB-INF/spring):

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
    http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">    

<!-- Root Context: defines shared resources visible to all other web components -->     
<context:annotation-config />

</beans>

我缺少什么?

谢谢。


你试过这个吗?

 <logger name="org.springframework.web">
     <level value="info" /> 
     <appender-ref ref="console" />     
 </logger>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Spring 框架下:警告:警告找不到记录器的附加程序(org.springframework.web.context.ContextLoader) 的相关文章

  • 如何在 log4j 中启用包级别日志记录

    谁能告诉我 log4j 中的包级别日志记录是什么 以及如何实现这一点 今天我的面试问题无法回答 即使我在谷歌中也没有找到好的解决方案 太感谢了 包级别日志记录是 log4j 的标准日志记录 使用 log4j 配置 您可以指定包和关联的级别
  • 无法识别的配置节 system.serviceModel

    当我将网站发布到我的 Plesk 服务器时 出现以下错误 无法识别的配置节 system serviceModel 您的主机支持哪个版本的 NET 框架 The
  • 使用log4j2.xml初始化slf4j

    我想使用 slf4j 而不是 log4j 我在 pom xml 中添加了以下依赖项 我对 slf4j 使用 1 7 25 对 log4j2 使用 2 10 0
  • 如何防止 IIS 默认站点 web.config 文件被虚拟目录继承?

    我在默认 IIS 站点的 web config 文件中有以下代码
  • 确定脚本所在的服务器以及 PHP 中的配置的最佳方法是什么?

    我正在尝试确定让 PHP 脚本确定脚本 站点当前在哪个服务器上运行的最佳方法 目前我有一个switch 使用 SERVER SERVER NAME SERVER SERVER PORT 以确定它位于哪个服务器上 然后 它根据其所在的服务器设
  • AspectJ 加载时间编织不适用于 Spring beans

    我正在开发一个项目 该项目使用 Spring 配置的 Java 而不是 xml 风格来连接依赖项 它还具有分析逻辑 应通过 AspectJ 将其编织到所需的方法上 通过注释 设置正在运行 我可以看到我想要的包中的类正在编织 并且分析信息已从
  • pgadmin4 : 无法联系 postgresql 应用程序服务器。

    我在 Windows 8 1 上安装了 PostgreSQL 9 6 2 但 pgadmin4 无法联系本地服务器 我尝试了 stackoverflow 中建议的几种解决方案 尝试卸载并重新安装 PostgreSQL 9 6 2 尝试修改
  • 如何导出 WAS 6.1 服务器配置

    有没有一种方法可以从 WAS 在 RAD 6 下运行 导出我的服务器设置 以便其他开发人员能够使用相同的脚本来设置他们的环境 要手动执行此操作 请在RAD 6 x 只需右键单击 服务器 视图中的服务器名称并选择以下选项之一 Export s
  • 配置 logback 以遵循 Java 配置,即 Logback 的纯 Java 配置

    我只是不喜欢 Logback 的 XML 或 Groovy 配置 更喜欢用 Java 进行配置 这也是因为我将在初始化后的不同时间在运行时更改配置 似乎对 Logback 进行 Java 配置的唯一方法是进行某种初始化劫持根追加器 http
  • 如何使用不同的类和导入动态地使用 Python 日志记录来更改文件句柄

    我无法执行即时日志文件句柄更改 例如 我有3节课 one py import logging class One def init self txt logging debug Hey I m the class One and I say
  • 如何将sublime text中的透明图像背景网格更改为不同的颜色

    When I get a preview of transparent PNGs in Sublime text I find it hard to see the content if it is white because of the
  • Grails Log4J 未登录生产环境

    我有一个 Grails 1 3 7 应用程序 并尝试在配置中设置 log4j 以用于生产 log4j 设置在开发中很好 但我无法在生产中显示任何内容 我正在尝试制作一个滚动文件等 但我无法显示任何内容 我什至在 信息 级别进行了配置 这样我
  • Azure 角色配置管理

    当您别无选择只能在 web config 或 app config 中保存配置设置时 我不明白 Windows Azure 如何让您改变应用程序的配置 例如 项目经常会使用大量使用 web config 的第三方库 web config 的
  • Spring Boot如何读取jar外部的属性文件

    在我的目标文件夹中 有 2 个文件夹 lib 和 conf 所有的属性文件都放在conf文件夹中 jar放在lib Folder中 在 Spring Boot 之前 我们在 spring xml 中使用以下配置来使用 value
  • 使用Log4j在日志中输出Spark应用程序id

    我有一个用于 Spark 应用程序的自定义 Log4j 文件 我想输出 Spark 应用程序 ID 以及消息和日期等其他属性 因此 JSON 字符串结构如下所示 name time date level thread message app
  • SLF4J 日志记录到文件 vs. DB vs. Solr

    我需要一些关于 SLF4J 日志记录的建议 目前 我们正在为 Java Web 应用程序使用 SLF4J 日志记录 log4j 绑定 该应用程序使用简单的 ConsoleAppender 我们的下一步是研究可以保存日志的地方 我们的应用程序
  • 为什么 StringValidator 对于自定义配置部分总是失败?

    我通过继承在 C 类库中创建了一个自定义配置部分ConfigurationSection 我在 Web 应用程序 也包括 C ASP NET 中引用了类库 填写了适当的属性 一切都运行良好 当我开始添加验证器时 问题就开始了 例如 这个属性
  • PHP_CodeSniffer - 显示失败的嗅探

    PHP CodeSniffer 中是否有设置来显示失败的嗅探 我将输出与我们的编码标准进行比较 并且一一使用很难破译哪个测试失败 看看我们可能想忽略哪个 如果有一种简单的方法来显示故障嗅探 那么我可以更轻松 更快地完成配置 您可以使用 s
  • PHP UTF-8 配置

    我正在使用 PHP 5 3 5 配置 Apache 2 2 17 服务器 我的目标是创建一个默认为内容类型的干净配置UTF 8 php ini default charset UTF 8 default mimetype applicati
  • 覆盖 logback 配置

    有什么方法可以覆盖 logback 配置吗 我知道我们在名为的文件中定义了 logback 配置logback xml 通常存储在路径中src main resources 并且我知道通过使用

随机推荐