-
Notifications
You must be signed in to change notification settings - Fork 41.7k
Description
A ConfigurationProperties class with a recursive subclass will not bind the recursive properties. I have tested this with Spring Boot 2.1.3.
This issue can be reproduced using the following application.properties file:
test.x.value: "Test1"
test.x.test.value: "Test2"
test.x.test.test.value: "Test3"
I would expect this application.properties to be bound to the TestProperties bean as TestProperties{x=Test{value='Test1', test=Test{value='Test2', test=Test{value='Test3', test=null}}}}, but Spring is only creating this: TestProperties{x=Test{value='Test1', test=null}}
Here is the ConfigurationProperties class (enabled with@EnableConfigurationProperties({TestProperties.class})):
@ConfigurationProperties(prefix = "test")
public class TestProperties {
static class Test {
private String value;
private Test test;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public Test getTest() {
return test;
}
public void setTest(Test test) {
this.test = test;
}
@Override
public String toString() {
return "Test{" +
"value='" + value + '\'' +
", test=" + test +
'}';
}
}
private Test x;
public Test getX() {
return x;
}
public void setX(Test x) {
this.x = x;
}
@Override
public String toString() {
return "TestProperties{" +
"x=" + x +
'}';
}
}In addition, the spring boot configuration processor does not support this class, it will throw a StackOverflowException.
See https://stackoverflow.com/questions/52906556/spring-configuration-properties-recursive-type