如何使用log4j2.xml中application.yml中定义的变量$ {variable}

时间:2018-05-02 03:32:46

标签: spring spring-boot

我遇到了与ApplicationListeners between ConfigFileApplicationListener and LoggingApplicationListener相同的问题,目的是使用${variable}application.yml中定义的变量log4j2.xml。但是spring boot 2.0使用log4j2LoggingApplicationListener订单仍在ConfigFileApplicationListener之前。

像pph一样

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
            <!--use log4j2-->
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jetty</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>
    <!--Needed for Async Logging with Log4j 2 -->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.lmax</groupId>
        <artifactId>disruptor</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
</dependencies>

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="warn">
<properties>
    <property name="baseDir">${log.path}</property>
    <property name="appName">${spring.application.name}</property>
</properties>

0 个答案:

没有答案