简体   繁体   English

Spring 引导环境后处理器未加载 application.properties

[英]Spring Boot EnvironmentPostProcessor not loading application.properties

I have a custom EnvironmentPostProcessor that adds a property to the environment.我有一个自定义 EnvironmentPostProcessor ,它向环境添加了一个属性。 In order to add this property correctly, I need to know a url, which is dependent on the profile that I am using, url that exists in every application property.为了正确添加此属性,我需要知道一个 url,它取决于我使用的配置文件 url,它存在于每个应用程序属性中。 Everything worked fine until I added as a dependency a local module, module which uses spring-cloud-starter-vault-config .一切正常,直到我添加一个本地模块作为依赖项,该模块使用spring-cloud-starter-vault-config Now the environment does not have the application properties values but has the values of the other module.现在环境没有应用程序属性值,但具有其他模块的值。 Please see below a visual representation:请看下面的视觉表示:

myProcessor
 - resources
   -- application.properties
   -- application-dev.properties
newlyAddedModdule/Dependency
 - resources
  -- application.properties

How can I make the project load the application.properties and not the other modules propertis?如何让项目加载 application.properties 而不是其他模块属性?

PS: I'd prefer a solution where I dont read the application properties files myself but rather have the ConfigurableEnvironment provide these for me, as it did before. PS:我更喜欢我自己不阅读应用程序属性文件的解决方案,而是让 ConfigurableEnvironment 像以前一样为我提供这些文件。

The best way would probably be to put the right value in the vault.最好的方法可能是将正确的值放入保险库中。 But I guess that not an options.但我想这不是一个选择。

Another way is to give the properties of the myProcessor a higher priority.另一种方法是赋予 myProcessor 的属性更高的优先级。 See Spring Externalized Configuration order请参阅Spring 外部化配置顺序

The easiest way I found is by putting the newlyAddedModule-properties in a jar, and the have myProcessor-properties strait on the classpath.我发现的最简单的方法是将newAddedModule-properties 放在jar 中,并在类路径上设置myProcessor-properties。

The easiest way I found (and that is working) was to rename my properties files under the following structure:我发现(并且有效)的最简单方法是在以下结构下重命名我的属性文件:

 - application.properties
 - bootstrap-dev.properties
 - bootstrap-prod.properties

as I needed properties under a certain profile the profile file will be loaded at the same time with the vault bootstrap因为我需要某个配置文件下的属性,所以配置文件将与 Vault 引导程序同时加载

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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