eclipse环境下启动springboot的坑


这两天在eclipse下启动springboot项目总是报:

Logging system failed to initialize using configuration from 'classpath:log4j2.xml'
java.io.FileNotFoundException: class path resource [log4j2.xml] cannot be resolved to URL because it does not exist
at org.springframework.util.ResourceUtils.getURL(ResourceUtils.java:137)
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:297)
at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:266)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:229)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:202)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)

经过网上查找,原因为springboot在获取resources时,使用的uri,如果yml文件里配置为

#============== log4j2 =================
logging:
config: classpath:log4j2.xml 

则此相对路径springboot加载uri是找不到的,只能配置为

#============== log4j2 =================
logging:
config: file:config/log4j2.xml

使用系统路径可以找到

 

如果在linux下,通过export classpath则无需改变路径。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM