Spring 命名application.properties的约定
在我的Spring应用程序中,我试图将属性占位符与配置文件Spring 命名application.properties的约定,spring,Spring,在我的Spring应用程序中,我试图将属性占位符与配置文件test、dev、prod一起使用。此外,我希望能够加载默认属性common,这些属性对于所有配置文件都是通用的 <context:property-placeholder ignore-resource-not-found="false" location="classpath:application-common.properties,classpath:application-t
test
、dev
、prod
一起使用。此外,我希望能够加载默认属性common
,这些属性对于所有配置文件都是通用的
<context:property-placeholder
ignore-resource-not-found="false"
location="classpath:application-common.properties,classpath:application-test.properties"/>
然而,这并不正确。我还没有使用变量${spring.profiles.active}
,因为即使没有它,它也不能正常工作。所发生的情况是,连字符应用程序-
之后的内容将按字母顺序加载。Loaded只是第一个,而忽略另一个。因此,在这种情况下,只加载-common
。奇怪的是,如果我删除连字符,它会同时加载两个文件
是否有我不知道的隐藏行为
@PropertySource({
“类路径:应用程序公共.properties”
})
spring.profiles.active
加载环境特定的属性文件
例如,spring.profiles.active=dev
一次需要多少个属性文件,为什么?想想看,在每次运行中,我只需要两个属性——所有配置文件的公共属性,然后是当前选定配置文件的属性。为什么否决投票是件坏事?
application.properties
是最常见的。。。您正在围绕框架而不是框架工作。Spring boot将加载应用程序.properties
和您的应用程序-{profile}.properties
(并按此顺序)。您试图通过智能化框架使事情变得更加复杂。我没有使用SpringBoot,我只是使用SpringContext。我应该如何描述属性占位符以在编写时加载application.properties和application-{profile}.properties?我尝试了classpath:application.properties,classpath:application-${spring.profiles.active}.properties
,但在这种情况下,只加载application.properties
,忽略了-test
。请添加一些有关所用spring版本的信息。