我正在试图找出在没有任何文件扩展名的SpringBoot应用程序中加载配置文件的选项。
例如,我有两个配置文件application.properties和机密,我提到使用外部位置。Spring忽略机密配置文件;但是,当我将secrets文件扩展名更改为properties/yml时,它就起作用了。
-Dspring.profiles.active=local
-Dspring.config.location=file:///<config location>/git/graphql-account/secrets,file:///<config location>/git/graphql-account/application-local.properties
我已经探索了Spring指南,但找不到解决方案。如何解决这个问题有什么建议吗?
注意:我使用的是openshift云,我需要加载它的机密,这些机密可在/opt/epaas/vault/secrets/secrets中获得。我不允许更改文件扩展名。
一种可能的解决方案是使用@PropertySource
注释:
@SpringBootApplication
@PropertySource("file:/etc/secrets")
public class Demo {
public static void main(...) {...}
}
/etc/secrets
是一个常规属性文件(键/值对,但没有扩展名(。
当然,如果你想配置/etc/secrets
的位置,你可以在@PropertySource
注释属性定义中使用SPEL:
@PropertySource(value="file:/${secrets.file.localtion}"