INFO: Initializing Spring root WebApplicationContext log4j:3个WARN卡死的解决

本文介绍了一种常见的情况:启动Tomcat时程序卡在特定阶段且无任何输出的情况。文章详细解释了这一现象背后的原因,并提供了解决方案,包括如何正确配置log4j.properties文件以捕获错误日志。

启动tomcat加载到这里卡死,没有任何输出,如下

INFO: 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.

等很长时间没有反应,这时很大可能是后台已经报错了,可能是文件加载过成功出现了死循环,导致启动不了,

ssm框架中可能是spring报错,然而因为没有配置log4j.properties文件导致日志没有输出,从而看不到报错,此时

需要增加log4j.properties文件,这个log4j文件只要放在src目录下就可以,log4j组件会自动加载log4j.properties文件,

看到报错后可以针对报错信息进行修改。

附上一个比较通用的log4j.properties文件(点击下载)



代码报错六月 10, 2025 9:51:26 上午 org.apache.coyote.AbstractProtocol init 信息: Initializing ProtocolHandler ["http-bio-8080"] 六月 10, 2025 9:51:26 上午 org.apache.catalina.core.StandardService startInternal 信息: Starting service Tomcat 六月 10, 2025 9:51:26 上午 org.apache.catalina.core.StandardEngine startInternal 信息: Starting Servlet Engine: Apache Tomcat/7.0.47 六月 10, 2025 9:51:28 上午 org.apache.catalina.core.ApplicationContext log 信息: No Spring WebApplicationInitializer types detected on classpath 六月 10, 2025 9:51:28 上午 org.apache.catalina.core.ApplicationContext log 信息: 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. 六月 10, 2025 9:51:31 上午 org.apache.catalina.core.StandardContext listenerStart 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bookService': Unsatisfied dependency expressed through field 'bookMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bookMapper' defined in file [D:\ideaworkspace\BookManagementSystem2\target\classes\com\example\book\dao\BookMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\ideaworkspace\BookManagementSystem2\target\classes\mapper\BookMapper.xml]'; nested exception is java.lang.IllegalArgumentException: Mapped Statements collection already contains value for com.example.book.dao.
06-11
:: Spring Boot :: (v3.4.5) 2025-06-03T20:31:00.850+08:00 INFO 7619 --- [ main] com.example.SpringbootApplication : Starting SpringbootApplication v0.0.1-SNAPSHOT using Java 24.0.1 with PID 7619 (/home/lcd/Travel.jar started by root in /home/lcd) 2025-06-03T20:31:00.866+08:00 INFO 7619 --- [ main] com.example.SpringbootApplication : No active profile set, falling back to 1 default profile: "default" 2025-06-03T20:31:07.993+08:00 INFO 7619 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8888 (http) 2025-06-03T20:31:08.076+08:00 INFO 7619 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2025-06-03T20:31:08.077+08:00 INFO 7619 --- [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.40] 2025-06-03T20:31:08.207+08:00 INFO 7619 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2025-06-03T20:31:08.210+08:00 INFO 7619 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 6813 ms Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter. 2025-06-03T20:31:13.444+08:00 INFO 7619 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] [root@iZ2ze5xhxzxsn3i91n5721Z lcd]# :: Spring Boot :: (v3.4.5) 2025-06-03T20:31:00.850+08:00 INFO 7619 --- [ main] com.example.SpringbootApplication : Starting SpringbootApplication v0.0.1-SNAPSHOT using Java 24.0.1 with PID 7619 (/home/lcd/Travel.jar started by root in /home/lcd) 2025-06-03T20:31:00.866+08:00 INFO 7619 --- [ main] com.example.SpringbootApplication : No active profile set, falling back to 1 default profile: "default" 2025-06-03T20:31:07.993+08:00 INFO 7619 --- [ main] o.s.b.w.emb
06-04
9月 17, 2025 1:51:05 下午 org.apache.catalina.core.StandardService startInternal 信息: Starting service [Tomcat] 9月 17, 2025 1:51:05 下午 org.apache.catalina.core.StandardEngine startInternal 信息: Starting Servlet engine: [Apache Tomcat/9.0.68] 9月 17, 2025 1:51:05 下午 org.apache.catalina.core.ApplicationContext log 信息: Initializing Spring embedded WebApplicationContext 25-09-17 13:51:05,748 INFO ServletWebServerApplicationContext:290 - Root WebApplicationContext: initialization completed in 1285 ms Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter. Registered plugin: 'com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor@1288222a' Parsed mapper file: 'file [D:\javaproject\Vue\music\online_music_server\target\classes\mapper\AdminMapper.xml]' Parsed mapper file: 'file [D:\javaproject\Vue\music\online_music_server\target\classes\mapper\CollectMapper.xml]' 25-09-17 13:51:06,006 WARN AnnotationConfigServletWebServerApplicationContext:591 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adminController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adminServiceImpl': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'adminMapper' defined in file [D:\javaproject\Vue\music\online_music_server\target\classes\com\niit\online_music_server\mapper\AdminMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/autoconfigure/MybatisPlusAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\javaproject\Vue\music\online_music_server\target\classes\mapper\ComsumerMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 72; 文档根元素 "mapper" 必须匹配 DOCTYPE 根 "null"。 25-09-17 13:51:06,015 INFO ConditionEvaluationReportLoggingListener:136 - Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 9月 17, 2025 1:51:06 下午 org.apache.catalina.core.StandardService stopInternal 信息: Stopping service [Tomcat] 25-09-17 13:51:06,030 ERROR SpringApplication:835 - Application run failed
09-18
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值