{"action":"opened","issue":{"url":"https://api.github.com/repos/spring-projects/spring-boot/issues/4828","labels_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/4828/labels{/name}","comments_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/4828/comments","events_url":"https://api.github.com/repos/spring-projects/spring-boot/issues/4828/events","html_url":"https://github.com/spring-projects/spring-boot/issues/4828","id":123512187,"number":4828,"title":"SpringApplicationContextLoader not loading properties in right order of precedence","user":{"login":"beverage","id":2602047,"avatar_url":"https://avatars.githubusercontent.com/u/2602047?v=3","gravatar_id":"","url":"https://api.github.com/users/beverage","html_url":"https://github.com/beverage","followers_url":"https://api.github.com/users/beverage/followers","following_url":"https://api.github.com/users/beverage/following{/other_user}","gists_url":"https://api.github.com/users/beverage/gists{/gist_id}","starred_url":"https://api.github.com/users/beverage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beverage/subscriptions","organizations_url":"https://api.github.com/users/beverage/orgs","repos_url":"https://api.github.com/users/beverage/repos","events_url":"https://api.github.com/users/beverage/events{/privacy}","received_events_url":"https://api.github.com/users/beverage/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-22T16:23:01Z","updated_at":"2015-12-22T16:23:01Z","closed_at":null,"body":"Hi,\r\n\r\nRelated to #2198 - while @TestPropertySource annotations are now providing environment variables from config files, they are not being applied in the correct order of precedence.\r\n\r\nMy understanding is that the external environment and config files are the lowest priority, followed by property source, test property source annotations, and lastly followed by test annotations (`@IntegrationTest`).\r\n\r\nHere is a test showing the current behaviors:\r\n```\r\n@RunWith(SpringJUnit4ClassRunner.class)\r\n@SpringApplicationConfiguration(classes = { SpringBootBugTest.Config.class, SpringBootBugTest.MoreConfig.class })  // Config is the same as earlier tests\r\n@WebAppConfiguration\r\n@TestPropertySource(locations  = \"classpath:/test.properties\",\r\n//\r\n// From config file:  \"value1=123\", \"value2=123\" \r\n    properties = {                  \"value2=456\",               \"value4=456\", \"value5=456\" })\r\n@IntegrationTest({    \"value1=789\",               \"value3=789\",               \"value5=789\" })\r\n//                    ------------  ------------  ------------  ------------  ------------\r\n// Expected results:   value1=789    value2=456    value3=789    value4=456    value5=789\r\npublic class SpringBootBugTest {\r\n\r\n    @Autowired \r\n    private SpringBootBugTest.MoreConfig moreConfig;\r\n\r\n    @Test\r\n    public void value1fromConfigIsOverridenByIntegrationTest() {\r\n        assertThat(moreConfig.getValue1(), equalTo(\"789\"));\r\n    }\r\n\r\n    @Test\r\n    public void value2fromConfigIsOverridenByTestPropertySource() {\r\n        assertThat(moreConfig.getValue2(), equalTo(\"456\"));\r\n    }\r\n\r\n    @Test\r\n    public void value3isFromIntegrationTest() {\r\n        assertThat(moreConfig.getValue3(), equalTo(\"789\"));\r\n    }\r\n\r\n    @Test\r\n    public void value4isFromTestPropertySource() {\r\n        assertThat(moreConfig.getValue4(), equalTo(\"456\"));\r\n    }\r\n\r\n    @Test\r\n    public void value5fromIntegrationTestIsOverridingTestPropertySource() {\r\n        assertThat(moreConfig.getValue5(), equalTo(\"789\"));\r\n    }\r\n\r\n    public static class MoreConfig {\r\n\r\n        @Value(\"${value1}\")\r\n        private String value1;\r\n\r\n        @Value(\"${value2}\")\r\n        private String value2;\r\n\r\n        @Value(\"${value3}\")\r\n        private String value3;\r\n\r\n        @Value(\"${value4}\")\r\n        private String value4;\r\n\r\n        @Value(\"${value5}\")\r\n        private String value5;\r\n\r\n        public String getValue1() {\r\n            return value1;\r\n        }\r\n\r\n        public String getValue2() {\r\n            return value2;\r\n        }\r\n\r\n        public String getValue3() {\r\n            return value3;\r\n        }\r\n\r\n        public String getValue4() {\r\n            return value4;\r\n        }\r\n\r\n        public String getValue5() {\r\n            return value5;\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nResults:\r\n1. 123 from config file is returned - expected 789from @IntegrationTest\r\n2. 123 from config file is returned - expected 456from @TestPropertySource\r\n3. Passes - 789 from @IntegrationTest is returned\r\n4. Passes - 456 from @TestPropertySource is returned\r\n5. Passes - 789 from @IntegrationTest is returned\r\n\r\nIt seems that [PropertySourceLocationsInitializer.initialize](https://github.com/spring-projects/spring-boot/blob/master/spring-boot/src/main/java/org/springframework/boot/test/SpringApplicationContextLoader.java#L263) that was added in the earlier commit is being called after loadContext. Is there a reason we are not loading the config file environment variables there, in loadContext, before checking the inlined properties?"}}