这两天在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则无需改变路径。