配置logback从jboss检索变量

ibrsph3r  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(231)

我在wildflyjboss容器中部署了几个.war文件。我想让它们使用wildfly配置中外部属性文件的属性。
我可以通过以下方式在beans/spring.xml中为bean工作:

<jee:jndi-lookup id="myProperties" jndi-name="java:jboss/properties/myproperties" />
    <bean id="exampleBean" class="com.package.beanclass">
        <constructor-arg index="0" value="${logfile.location}"/>
    </bean>

但是我试图通过logback.xml文件从这个外部属性文件引用${logfile.location}变量。
我试过:

<configuration>
      <property file="java:jboss/properties/myproperties"/>
      <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>{logfile.location}/logFile.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
          <!-- daily rollover -->
          <fileNamePattern>{logfile.location}/logFile.%d{yyyy-MM-dd}.log</fileNamePattern>

          <maxHistory>30</maxHistory>
        </rollingPolicy>

        <encoder>
          <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
        </encoder>
      </appender> 

      <root level="DEBUG">
        <appender-ref ref="FILE" />
      </root>
    </configuration>

我试着把“文件”换成“资源”。
但我总是得到:

File property is set to [log.location_IS_UNDEFINED ..

要从这个外部属性文件中读取值以便从logback.xml中读取值,我需要做什么?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题