-
Notifications
You must be signed in to change notification settings - Fork 41.4k
Description
Hi! In migrating to Spring Boot 2 I came across a curious mismatch in our properties, illustrated in the following project & test: https://github.com/timtebeek/env-matching/blob/master/src/test/java/com/github/timtebeek/envmatching/EnvMatchingApplicationTests.java#L29
My application is nothing more than:
@Data
@SpringBootApplication
@ConfigurationProperties("sample")
@Validated
public class EnvMatchingApplication {
private String someProp1;
private String oAuthProp2;
public static void main(String[] args) {
SpringApplication.run(EnvMatchingApplication.class, args);
}
}
But when I run my simple JUnit test:
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
"sample.someProp1=bla",
"sample.oAuthProp2=bla",
})
public class EnvMatchingApplicationTests {
@Autowired
private TestRestTemplate restTemplate;
@Test
public void contextLoads() {
ResponseEntity<String> entity = restTemplate.getForEntity("/actuator/configprops", String.class);
assertThat(entity.getStatusCode()).isEqualByComparingTo(HttpStatus.OK);
assertThat(entity.getBody()).contains("someProp1");
assertThat(entity.getBody()).contains("oAuthProp2");
}
}
It fails on the final assertion. So sample.someProp1
is matched perfectly fine, whereas sample.oAuthProp2
is not matched. In our case this leads to misconfiguration(!) and some confusion. I've found the workaround to be to lowercase the property, but that's quite surprising to me. Can you enlighten me if I'm correct in having assumed this would work?
I'm aware there were substantial changes to the relaxed binding in Spring Boot 2, but never expected the second character being uppercase to be a problem at all. An uppercase letter as third character also work fine, so really weird behavior here.