@ -72,6 +72,7 @@ import org.springframework.boot.testsupport.system.OutputCaptureExtension;
import org.springframework.context.annotation.AnnotationConfigApplicationContext ;
import org.springframework.context.annotation.AnnotationConfigApplicationContext ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Bean ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.context.annotation.Configuration ;
import org.springframework.context.annotation.Import ;
import org.springframework.context.annotation.ImportResource ;
import org.springframework.context.annotation.ImportResource ;
import org.springframework.context.annotation.Scope ;
import org.springframework.context.annotation.Scope ;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer ;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer ;
@ -1152,6 +1153,14 @@ class ConfigurationPropertiesTests {
assertThat ( bean . getNested ( ) . name ( ) ) . isEqualTo ( "spring" ) ;
assertThat ( bean . getNested ( ) . name ( ) ) . isEqualTo ( "spring" ) ;
}
}
@Test
void loadWhenPotentiallyConstructorBoundPropertiesAreImportedUsesJavaBeanBinding ( ) {
load ( PotentiallyConstructorBoundPropertiesImporter . class , "test.prop=alpha" ) ;
PotentiallyConstructorBoundProperties properties = this . context
. getBean ( PotentiallyConstructorBoundProperties . class ) ;
assertThat ( properties . getProp ( ) ) . isEqualTo ( "alpha" ) ;
}
private AnnotationConfigApplicationContext load ( Class < ? > configuration , String . . . inlinedProperties ) {
private AnnotationConfigApplicationContext load ( Class < ? > configuration , String . . . inlinedProperties ) {
return load ( new Class < ? > [ ] { configuration } , inlinedProperties ) ;
return load ( new Class < ? > [ ] { configuration } , inlinedProperties ) ;
}
}
@ -3004,4 +3013,34 @@ class ConfigurationPropertiesTests {
static record NestedRecord ( String name ) {
static record NestedRecord ( String name ) {
}
}
@EnableConfigurationProperties
@Import ( PotentiallyConstructorBoundProperties . class )
static class PotentiallyConstructorBoundPropertiesImporter {
@Bean
String notAProperty ( ) {
return "notAProperty" ;
}
}
@ConfigurationProperties ( "test" )
static class PotentiallyConstructorBoundProperties {
private String prop ;
PotentiallyConstructorBoundProperties ( String notAProperty ) {
}
String getProp ( ) {
return this . prop ;
}
void setProp ( String prop ) {
this . prop = prop ;
}
}
}
}