Java 如何在Spring boot中加载没有任何文件扩展名的配置文件
我试图找出在SpringBoot应用程序中加载配置文件的选项,该应用程序没有任何文件扩展名 e、 我有两个配置文件application.properties和secrets,我提到使用外部位置。Spring忽略机密配置文件;但是,当我将secrets文件扩展名更改为properties/yml时,它可以工作Java 如何在Spring boot中加载没有任何文件扩展名的配置文件,java,spring,spring-boot,Java,Spring,Spring Boot,我试图找出在SpringBoot应用程序中加载配置文件的选项,该应用程序没有任何文件扩展名 e、 我有两个配置文件application.properties和secrets,我提到使用外部位置。Spring忽略机密配置文件;但是,当我将secrets文件扩展名更改为properties/yml时,它可以工作 -Dspring.profiles.active=local \ -Dspring.config.location=file:///<config location>/git/
-Dspring.profiles.active=local \
-Dspring.config.location=file:///<config location>/git/graphql-account/secrets,file:///<config location>/git/graphql-account/application-local.properties
-Dspring.profiles.active=local\
-Dspring.config.location=file:////git/graphql-account/secrets,file:////git/graphql-account/application-local.properties
我已经探索过,但找不到解决方案。
对如何解决这个问题有什么建议吗
注意:我正在使用openshift cloud,我需要加载它的机密,这些机密可在/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}"
为什么不将其命名为
secrets.properties
或secrets.yml
?我正在使用openshift cloud,需要从location-/opt/epaas/vault/secrets/secrets加载其机密。不允许我更改文件扩展名