使用spring容器时,服务器不能顺利启动信息: Initializing Spring root WebApplicationContext log4j:WARN No appenders cou

本文介绍了在遇到Spring服务器启动时初始化WebApplicationContext失败和Log4j警告的问题。主要原因是web.xml中缺少必要的listener配置。通过在web.xml中添加相关配置,并更新log4j配置文件,可以解决这个问题。当服务器成功启动,会打印出一系列初始化日志,包括Hibernate和c3p0数据源的配置信息。最后,错误日志显示数据库连接被拒绝,提示应检查数据库用户名和密码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

错误信息

在出现以下信息:

信息: Initializing Spring root WebApplicationContext 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.

和服务器错误信息
图片

web.xml的spring配置

<listener> 
    <listener-class>
    org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

只有以上的listener,但是它的文档写着

    Bootstrap listener to start up and shut down Spring’s root WebApplicationContext. Simply delegates
to ContextLoader as well as to ContextCleanupListener.
    This listener should be registered after org.springframework.web.util.Log4jConfigListener in web.xml,
if the latter is used.

    As of Spring 3.1, ContextLoaderListener supports injecting the root web application context via the
ContextLoaderListener(WebApplicationContext) constructor, allowing for programmatic configuration
in Servlet 3.0+ environments. See org.springframework.web.WebApplicationInitializer for usage
examples.

需要修改的地方

  • web.xml

                
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值