如何在Spring Boot中加载没有任何扩展名的配置文件

我正在尝试找出在没有任何文件扩展名的SpringBoot应用程序中加载配置文件的选项。

例如我有2个配置文件application.properties和我使用外部位置提到的秘密。 Spring会忽略秘密配置文件;但是,当我将秘密文件扩展名更改为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 guide,但找不到解决方案。 有什么建议可以解决这个问题吗?

注意:我正在使用openshift云,我需要加载 / opt / epaas / vault / secrets / secrets 中可用的机密。我不允许更改文件扩展名。

jjj22 回答:如何在Spring Boot中加载没有任何扩展名的配置文件

一种可能的解决方案是使用@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}"
本文链接:https://www.f2er.com/3164225.html

大家都在问