Spring Boot 使用 PropertySource 顺序,旨在允许合理地覆盖值,属性按以下顺序考虑:
- 命令行参数。
- 来自 SPRING_APPLICATION_JSON 的属性(嵌入环境变量或系统属性中的内联 JSON)
- 来自 java:comp/env 的 JNDI 属性。
- Java 系统属性 (System.getProperties())。
- 操作系统环境变量。
- 仅具有 random.* 属性的 RandomValuePropertySource。
- 打包 jar 之外的特定于配置文件的应用程序属性(application-{profile}.properties 和 YAML 变体)
- 打包在 jar 内的特定于配置文件的应用程序属性(application-{profile}.properties 和 YAML 变体)
- 打包的 jar 之外的应用程序属性(application.properties 和 YAML 变体)。
- 打包在 jar 内的应用程序属性(application.properties 和 YAML 变体)。
- @Configuration 类上的 @PropertySource 注释。
- 默认属性(使用 SpringApplication.setDefaultProperties 指定)。
但我不喜欢这个。我怎样才能改变它?