Skip to content

Commit f60547c

Browse files
committed
Merge branch '3.1.x'
Closes gh-36360
2 parents b66eea8 + 218f4f2 commit f60547c

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBean.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,6 @@ public static ConfigurationPropertiesBean get(ApplicationContext applicationCont
216216
if (bindTarget.getBindMethod() == null && factoryMethod != null) {
217217
bindTarget = bindTarget.withBindMethod(JAVA_BEAN_BIND_METHOD);
218218
}
219-
if (bindTarget.getBindMethod() == null) {
220-
bindTarget = bindTarget.withBindMethod(deduceBindMethod(bindTarget));
221-
}
222219
if (bindTarget.getBindMethod() != VALUE_OBJECT_BIND_METHOD) {
223220
bindTarget = bindTarget.withExistingValue(bean);
224221
}

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesTests.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
7373
import org.springframework.context.annotation.Bean;
7474
import org.springframework.context.annotation.Configuration;
75+
import org.springframework.context.annotation.Import;
7576
import org.springframework.context.annotation.ImportResource;
7677
import org.springframework.context.annotation.Scope;
7778
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
@@ -1164,6 +1165,14 @@ void loadWhenNestedRecordWithExistingInstance() {
11641165
assertThat(bean.getNested().name()).isEqualTo("spring");
11651166
}
11661167

1168+
@Test
1169+
void loadWhenPotentiallyConstructorBoundPropertiesAreImportedUsesJavaBeanBinding() {
1170+
load(PotentiallyConstructorBoundPropertiesImporter.class, "test.prop=alpha");
1171+
PotentiallyConstructorBoundProperties properties = this.context
1172+
.getBean(PotentiallyConstructorBoundProperties.class);
1173+
assertThat(properties.getProp()).isEqualTo("alpha");
1174+
}
1175+
11671176
private AnnotationConfigApplicationContext load(Class<?> configuration, String... inlinedProperties) {
11681177
return load(new Class<?>[] { configuration }, inlinedProperties);
11691178
}
@@ -3019,4 +3028,34 @@ void setNested(NestedRecord nestedRecord) {
30193028
static record NestedRecord(String name) {
30203029
}
30213030

3031+
@EnableConfigurationProperties
3032+
@Import(PotentiallyConstructorBoundProperties.class)
3033+
static class PotentiallyConstructorBoundPropertiesImporter {
3034+
3035+
@Bean
3036+
String notAProperty() {
3037+
return "notAProperty";
3038+
}
3039+
3040+
}
3041+
3042+
@ConfigurationProperties("test")
3043+
static class PotentiallyConstructorBoundProperties {
3044+
3045+
private String prop;
3046+
3047+
PotentiallyConstructorBoundProperties(String notAProperty) {
3048+
3049+
}
3050+
3051+
String getProp() {
3052+
return this.prop;
3053+
}
3054+
3055+
void setProp(String prop) {
3056+
this.prop = prop;
3057+
}
3058+
3059+
}
3060+
30223061
}

spring-boot-project/spring-boot/src/test/kotlin/org/springframework/boot/context/properties/KotlinConfigurationPropertiesTests.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry
2222
import org.springframework.beans.factory.support.RootBeanDefinition
2323
import org.springframework.context.annotation.AnnotationConfigApplicationContext
2424
import org.springframework.context.annotation.Configuration
25+
import org.springframework.context.annotation.Import
2526
import org.springframework.test.context.support.TestPropertySourceUtils
2627

2728
import org.assertj.core.api.Assertions.assertThat
@@ -68,6 +69,14 @@ class KotlinConfigurationPropertiesTests {
6869
assertThat(properties.inner.bravo).isEqualTo("two")
6970
}
7071

72+
@Test
73+
fun `mutable data class properties can be imported`() {
74+
this.context.register(MutableDataClassPropertiesImporter::class.java)
75+
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(this.context, "mutable.prop=alpha");
76+
this.context.refresh();
77+
assertThat(this.context.getBean(MutableDataClassProperties::class.java).prop).isEqualTo("alpha")
78+
}
79+
7180
@ConfigurationProperties(prefix = "foo")
7281
class BingProperties(@Suppress("UNUSED_PARAMETER") bar: String) {
7382

@@ -106,4 +115,15 @@ class KotlinConfigurationPropertiesTests {
106115

107116
}
108117

118+
@EnableConfigurationProperties
119+
@Configuration(proxyBeanMethods = false)
120+
@Import(MutableDataClassProperties::class)
121+
class MutableDataClassPropertiesImporter {
122+
}
123+
124+
@ConfigurationProperties(prefix = "mutable")
125+
data class MutableDataClassProperties(
126+
var prop: String = ""
127+
)
128+
109129
}

0 commit comments

Comments
 (0)