美文网首页
no applicable action for [spring

no applicable action for [spring

作者: 开始懂了90 | 来源:发表于2023-05-07 23:37 被阅读0次
    1. springboot项目配置logback.xml 文件时报错
    Caused by: java.lang.IllegalStateException: Logback configuration error detected: 
    ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:94 - no applicable action for [springProperty], current ElementPath  is [[configuration][springProperty]]
    ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:102 - no applicable action for [springProperty], current ElementPath  is [[configuration][springProperty]]
    ERROR in ch.qos.logback.core.joran.spi.Interpreter@6:100 - no applicable action for [springProperty], current ElementPath  is [[configuration][springProperty]]
     at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:179)
     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:132)
     at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:332)
     ... 18 more
    
    1. logback.xml 文件配置
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration scan="true" scanPeriod="60 seconds">
        <springProperty scope="context" name="applicationName" source="spring.application.name"/>
        <springProperty scope="context" name="level" source="logback.logging.level" defaultValue="info"/>
        <springProperty scope="context" name="env" source="spring.profiles.active" defaultValue="dev"/>
    
        <!--为了防止进程退出时,内存中的数据丢失,请加上此选项-->
        <shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>
        <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
            <encoder>
                <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
            </encoder>
        </appender>
    
        <property name="LOGSTASH_ADDRESS" value="127.0.0.1:7890"/>
        <appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
            <destination>${LOGSTASH_ADDRESS}</destination>
            <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
                <providers>
                    <timestamp>
                        <timeZone>UTC</timeZone>
                    </timestamp>
                    <pattern>
                        <pattern>
                            {
                            "app": "${applicationName}",
                            "env": "${env}",
                            "level": "%-5level",
                            "thread": "%thread",
                            "logger": "%logger{50} %M %L ",
                            "message": "%msg%n",
                            "stack_trace": "%exception"
                            }
                        </pattern>
                    </pattern>
                </providers>
            </encoder>
        </appender>
    
    
        <root level="${level}">
            <appender-ref ref="STDOUT"/>
    <!--        <appender-ref ref="LOGSTASH"/>-->
        </root>
    
    </configuration>
    
    
    1. 解决办法
      3.1 将resources 下的 logback.xml 重命名为logback-spring.xml(官方建议)
      3.2 将application.yml 中
    logging:
      config: classpath:logback.xml 
    

    替换为

    logging:
      config: classpath:logback-spring.xml
    

    3.3 重启服务

    1. 原因分析:和springboot加载日志配置顺序有关,默认自带日志,未深究

    相关文章

      网友评论

          本文标题:no applicable action for [spring

          本文链接:https://www.haomeiwen.com/subject/eavksdtx.html