有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java日志存储未正确读取spring属性

因此,我有一个非常简单的logstash配置,可以从spring读取主机URL。尽管出于某种原因,它不起作用

我的logback-spring.xml看起来有点像这样:

  <springProperty name="logstashDestination" scope="context" source="service.logstash.host"/>
  <appender class="net.logstash.logback.appender.LogstashTcpSocketAppender" name="LOGSTASH">
    <destination>${logstashDestination}</destination>

    <!-- encoder is required -->
    <encoder class="net.logstash.logback.encoder.LogstashEncoder">
      <customFields>{"service":"provisioning-engine-jane"}</customFields>
    </encoder>
  </appender>

在我的application.properties中,我有以下几行:

spring.profiles.active:sit
service.logstash.host:NaN

在{}中,我有一行:

service.logstash.host:api-test.local:9013

这会导致整个应用程序因错误而崩溃

Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
    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.util.PropertySetter@44cb3536 - Could not invoke method addDestination in class net.logstash.logback.appender.LogstashTcpSocketAppender with parameter of type java.lang.String java.lang.reflect.InvocationTargetException
ERROR in net.logstash.logback.appender.LogstashTcpSocketAppender[LOGSTASH] - No destination was configured. Use <destination> to add one or more destinations to the appender

奇怪的是,如果我添加一个带有一些伪数据的bootstrap.properties文件,它就会启动。问题是虚拟数据覆盖了我的特定于环境的日志存储URL

有人知道为什么会这样吗


共 (0) 个答案