gpt4 book ai didi

java - 在 Spring Cloud Config 之前读取 Logback SpringProperties 导致错误

转载 作者:行者123 更新时间:2023-12-02 12:57:21 26 4
gpt4 key购买 nike

我在应用程序中有一个 logback-spring.xml 文件,并且我正在使用 springProperties,如下例所示

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<springProperty name="event.pattern" source="my.logging.event.pattern"/>

我的 springProperties 的值在 spring cloud config .yml 文件中设置

my:
logging:
activated: true
appender:
waitStrategyType: sleeping
encoder:
includeCallerData: true
includeMdc: false
event:
maxSize: 15000
pattern: |
{
"message": "%.-${my.logging.event.maxSize}msg",
"req": {
"url": "%mdc{req.url}",
"headers": {
"x-request-id": "%mdc{req.headers.x-request-id}"
}
},
"application": {
"name": "${spring.application.name}"
}
}

不幸的是,当我启动我的应用程序时遇到错误:

ERROR in net.logstash.logback.composite.loggingevent.LoggingEventPatternJsonProvider@44a2b17b - Failed to parse pattern [event.pattern_IS_UNDEFINED] com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'event': was expecting ('true', 'false' or 'null')

这是因为logback-spring.xml是在外部化配置之前读取的

解决这个问题的最佳方案是什么?

最佳答案

loback-spring.xml 重命名为 myConfig.xml

将其添加到您的 application.yml

logging.config: classpath:myConfig.xml

它适用于“application.yml”中定义的值,但对于 spring-cloud-config 来说可能还为时过早。

关于java - 在 Spring Cloud Config 之前读取 Logback SpringProperties 导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53597034/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com