springboot 的web项目配置文件application.properties在jar包内外的问题

springboot 的web项目
在maven pom文件里,spring-boot-maven-plugin和maven-resources-plugin都存在

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>

        <!-- resource插件 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>3.0.2</version><!--$NO-MVN-MAN-VER$ -->
        </plugin>
    </plugins>
</build>

这样的话,打的jar包里包含applications.properties(称为A)
在生产环境运行的时候,这个jar包和另一个applications.properties(称为B)同时在一个文件夹内
那么B会覆盖A的配置吗?为何?

阅读 6.8k
2 个回答
新手上路,请多包涵

楼主试过吗?我觉得不会,

https://docs.spring.io/spring...

  1. A /config subdirectory of the current directory.
  2. The current directory
  3. A classpath /config package
  4. The classpath root

The list is ordered by precedence (properties defined in locations higher in the list override those defined in lower locations).

根据 spring-boot 官方描述, 那些较低顺序加载的配置会覆盖较高配置的加载. 换句话说就是A classpath /config package的配置会覆盖The classpath root中的配置.

$ java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题