Spring Boot外部配置覆盖不起作用

时间:2019-09-12 12:54:01

标签: spring-boot

我的资源文件夹中有一个application.ymlapplication-qa.yml。 我有一个外部application-qa.yml。 我希望外部application-qa.yml中的属性覆盖默认application.yml和内部application-qa.yml中的匹配属性,我不想覆盖整个文件。

我正在添加此VM选项(在Intellij中):-Dspring.config.additional-location=file:{absolute/path/to/external/ending/with/application-qa.yml}

我也有env变量(也有Intellij):spring.profiles.active=qa

由于某种原因,覆盖无效,我从内部application-qa.yml而不是外部application.yml获取值。

尝试将外部文件命名为application-qa.yml,没有用。

更新:

如果我从路径末尾删除 var dataInJson = [ { data: { name: 'b1', street: 's1', city: 'c1', departments: 10, offices: 15 }, kids: [ { data: { department: 'HR', supervisor: 'Isidor Bristol', floor: 1, employees: 15 }, kids: [ { data: { name: 'Klement Nikodemos', phone: '+938462', hire_date: 'January 1, 2010', id: 3456 }, kids: [] }, { data: { name: 'Madhava Helmuth', phone: '+348902', hire_date: 'May 23, 2002', id: 1234 }, kids: [] }, { data: { name: 'Andria Jesse', phone: '456123', hire_date: 'October 23, 2011', id: 9821 }, kids: [] } ] }, { data: { department: 'development', supervisor: 'Jim Linwood', floor: 2, employees: 18 }, kids: [ { data: { name: 'Origenes Maxwell', phone: '345892', hire_date: 'February 1, 2004', id: 6234 }, kids: [] } ] }, { data: { department: 'testing', supervisor: 'Zekeriya Seok', floor: 4, employees: 11 }, kids: [] } ] }, { data: { name: 'b2', street: 's10', city: 'c2', departments: 3, offices: 10 }, kids: [ { data: { department: 'development', supervisor: 'Gallagher Howie', floor: 8, employees: 24 }, kids: [ { data: { name: 'Wat Dakota' }, kids: [] } ] }, { data: { department: 'testing', supervisor: 'Shirley Gayle', floor: 4, employees: 11 }, kids: [] } ] }, { data: { name: 'b3', street: 's3', city: 'c3', departments: 2, offices: 1 }, kids: [ { data: { department: 'development' }, kids: [ { data: { name: 'Wat Dakota' }, kids: [] } ] }, {} ] }, { data: { name: 'b4', city: 'c4' }, kids: [] } ];并给出文件所在文件夹的路径,它确实可以工作,但是我想指定一个文件,我不希望他接受所有的内容目录。

1 个答案:

答案 0 :(得分:0)

这是从1.x到2.x的行为更改。 spring.config.location将覆盖默认值,而不是添加到默认值。我们需要使用spring.config.additional-location来保持默认值。因此,如果要覆盖,请尝试使用spring.config.location。