您现在的位置是:网站首页 > 代码编程 > JAVA开发JAVA开发
【原】记一次logback配置文件命名导致项目启动失败的问题记录
不忘初心 2019-12-21 围观() 评论() 点赞() 【JAVA开发】
简介:logback不是第一次用了,以前从来没在意过它的配置文件命名,基本上都是拷贝过来拷贝过去,这次的新项目中破天荒么有拷贝,结果就报错了:java.lang.IllegalStateException: Logback configuration error detected:ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:70 - no a
logback不是第一次用了,以前从来没在意过它的配置文件命名,基本上都是拷贝过来拷贝过去,这次的新项目中破天荒么有拷贝,结果就报错了:java.lang.IllegalStateException: Logback configuration error detected:ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:70 - no applicable action for [springProperty], current ElementPath is [[configuration][springProperty]]。
详细错误信息如下:
Logging system failed to initialize using configuration from 'classpath:logback.xml'
java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:70 - no applicable action for [springProperty], current ElementPath is [[configuration][springProperty]]
at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:57)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:118)
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:318)
at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:288)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:246)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:223)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:76)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
at com.jjld.coupon.Application.main(Application.java:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
2019-12-21 13:37:58 [restartedMain] [ERROR] [org.springframework.boot.SpringApplication:826] - Application run failed
java.lang.IllegalStateException: java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:70 - no applicable action for [springProperty], current ElementPath is [[configuration][springProperty]]
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:324)
at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:288)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:246)
at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:223)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:76)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
at com.jjld.coupon.Application.main(Application.java:10)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:70 - no applicable action for [springProperty], current ElementPath is [[configuration][springProperty]]
at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169)
at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66)
at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:57)
at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:118)
at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:318)
... 19 common frames omitted
错误提示倒是蛮清晰,就是说我logback.xml文件中的springProperty标签识别不了。
我的logback配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<!--用springProperty来配置的话,可以直接读取properties文件-->
<springProperty scope="context" name="LOG-DIR" source="log.dir"/>
<!--<property name="LOG-DIR" value="/home/admin/logs"/>-->
<property name="APP-NAME" value="coupon"/>
<property name="LOG-PATTERN" value="%d{yyyy-MM-dd HH:mm:ss} [%thread] [%-5level] [%class:%line] - %m%n"/>
<!--控制台-->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!--<charset>UTF-8</charset>-->
<pattern>${LOG-PATTERN}</pattern>
</encoder>
</appender>
<!--日志文件-->
<appender name="FILE-ALL" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--滚动策略,按照时间滚动 TimeBasedRollingPolicy-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--文件路径,定义了日志的切分方式,把每一天的日志归档到一个文件中,以防止日志填满整个磁盘空间-->
<FileNamePattern>${LOG-DIR}/${APP-NAME}/${APP-NAME}-%d{yyyyMMdd}.log</FileNamePattern>
<!--只保留最近10天的日志-->
<maxHistory>10</maxHistory>
<!--用来指定日志文件的上限大小,那么到了这个值,就会删除旧的日志-->
<!--<totalSizeCap>1GB</totalSizeCap>-->
</rollingPolicy>
<!--日志输出编码格式化-->
<encoder>
<!--<charset>UTF-8</charset>-->
<pattern>${LOG-PATTERN}</pattern>
</encoder>
</appender>
<!-- ERROR日志文件 -->
<appender name="FILE-ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<!--过滤 ERROR-->
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<!--滚动策略,按照时间滚动 TimeBasedRollingPolicy-->
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!--文件路径,定义了日志的切分方式——把每一天的日志归档到一个文件中,以防止日志填满整个磁盘空间-->
<FileNamePattern>${LOG-DIR}/${APP-NAME}/${APP-NAME}-error-%d{yyyyMMdd}.log</FileNamePattern>
<!--只保留最近10天的日志-->
<maxHistory>10</maxHistory>
<!--用来指定日志文件的上限大小,那么到了这个值,就会删除旧的日志-->
<!--<totalSizeCap>1GB</totalSizeCap>-->
</rollingPolicy>
<!--日志输出编码格式化-->
<encoder>
<!--<charset>UTF-8</charset>-->
<pattern>${LOG-PATTERN}</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE-ALL"/>
<appender-ref ref="FILE-ERROR"/>
</root>
<!--<logger name="com.jjld.coupon.repository" level="DEBUG"/>-->
<!--<logger name="com.jjld.coupon.mapper" level="DEBUG"/>-->
</configuration>
仔细检查了一番,虽然这次没拷贝,但是也确定没有写错标签,比对了以前的项目,发现唯一不一样的就是文件名,以前的项目中的配置文件都是logback-xxx.xml,而我这次直接偷懒写成了logback.xml,可能问题就是出在这里,又偷了个懒,没有手动测试,直接百度了一番,发现已经有前辈大佬踩过这个坑了。
如果项目中配置的日志文件的名称是logback.xml的话,logback会先与Spring之前加载日志配置,这时日志文件中的springProfile的配置是无效的。按照官方文档的说法将logback.xml改为logback-spring.xml就可以了。
问题原因找到了,果然是文件命名导致的,直接改成logback-spring.xml或者locback-xxx.xml之后,项目启动恢复正常。。。
看完文章,有任何疑问,请加入群聊一起交流!!!
很赞哦! ()
相关文章
标签云
猜你喜欢
- IntelliJ IDEA 2019.2已经可以利用补丁永久破解激活了
- IntelliJ IDEA 2019.3利用补丁永久破解激活教程
- IntelliJ IDEA高版本最灵活的永久破解激活方法(含插件激活,时长你说了算)
- Jetbrains全家桶基于ja-netfilter的最新破解激活详细图文教程
- IntelliJ IDEA 2022.1永久破解激活教程(亲测可用,持续更新)
- 分享几个正版 IntelliJ IDEA 激活码(破解码、注册码),亲测可用,持续更新
- ja-netfilter到底需不需要mymap,2021.3.2版本激活失效?
- 如何激活idea2022.1及以上版本中的插件(亲测可用)
- 【史上最全】IntelliJ IDEA最新2022.1版本安装和激活视频教学(含插件)
- IntelliJ IDEA 2022.2 版本最新2099年永久激活方法,亲测可用,也可以开启新UI了。
站点信息
- 网站程序:spring + freemarker
- 主题模板:《今夕何夕》
- 文章统计:篇文章
- 标签管理:标签云
- 微信公众号:扫描二维码,关注我们