简体   繁体   中英

Spring Boot + Logback - external config vs local config

I have a Spring Boot app with a local application.properties file, containing among others:

logging.config=src/main/resources/local/logback-dev.xml

In this logback-dev.xml file, there is a file appender with a local path (say /local/path/log/)

When deploying to a different environment (say PROD), the guy who deploy uses his own application.properties file as externalized configuration (--spring.config.location=...), containing among others:

logging.config=/prod/path/logback-prod.xml

In that logback-prod.xml file, there is a file appender with a different path (say /prod/path/log/)

When running the application, an error rises, as it seems both files are utilized: we get in the log present in /prod/path/log/ messages such as " cannot find path /local/path/log/ "

Could someone explain what's happening here? I thought the externalized config would override the local one, but something is odd here.

We have the same problem and have found a solution with the help of this documentation: External Configuration https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config Application Properties https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-application-property-files

In Pom we added:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <excludes>
                    <exclude>**/application.properties</exclude>
                    <exclude>**/application-development.properties</exclude>
                    <exclude>**/application-production.properties</exclude>
                    <exclude>**/logback.xml</exclude>
                </excludes>
            </configuration>
        </plugin>

Hope this will solve your problem and helping to understand.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM