Spring Boot 配置文件和日志文件放到jar之外

1.设置打包jar的时候排除文件

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <excludes>
            <exclude>*.properties</exclude>
            <exclude>logback.xml</exclude>
        </excludes>
    </resource>
</resources>

2.启动的时候传入参数指定位置

src/main/resources *.properties logback.xml 2.启动的时候传入参数指定位置
java -jar xxx.jar --spring.config.location=D:springconfig  --logging.config=D:springconfiglogback.xml java -jar xxx.jar --spring.config.location=D:springconfig --logging.config=D:springconfiglogback.xml
springboot 默认找配置文件的位置如下 springboot 默认找配置文件的位置如下
// Note the order is from least to most specific (last one wins)
private static final String DEFAULT_SEARCH_LOCATIONS = "classpath:/,classpath:/config/,file:./,file:./config/";

// Note the order is from least to most specific (last one wins) private static final String DEFAULT_SEARCH_LOCATIONS = "classpath:/,classpath:/config/,file:./,file:./config/";
经验分享 程序员 微信小程序 职场和发展