-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Description
Steven Schlansker opened SPR-14602 and commented
I have an @Configuration class which holds some internal configuration data. It wants to instantiate a collaborating @Configuration class, hand off some data to it, and expects its collaborator to exist. However, it seems that an @Bean method that returns a @Configuration class fails because its BeanDefinition#getBeanClassName is null, so ConfigurationClassUtils#checkConfigurationClassCandidate returns false.
@RunWith(SpringRunner.class)
@ContextConfiguration(classes=BeanDefinitionAutowireTest.Config.class)
public class BeanDefinitionAutowireTest {
@Configuration
public static class InnerConfig {
@Bean
URI someUri() {
return URI.create("/");
}
}
@Configuration
public static class Config {
@Bean
public InnerConfig innerConfig() {
return new InnerConfig();
}
}
@Autowired
URI someUri;
@Test
public void testUri() {
assertNotNull(someUri);
}
}
I feel that this should work. If for some reason it can not, it should throw an exception or otherwise fail obviously, rather than silently discarding the definitions you expect.
(Note that this test case is a little simplified, in the real case I pass constructor arguments to InnerConfig, so making things static is not an option)
Affects: 4.3.1
Issue Links:
- Allow BeanDefinitionRegistryPostProcessor to register other BeanDefinitionRegistryPostProcessors [SPR-10630] #15258 Allow BeanDefinitionRegistryPostProcessor to register other BeanDefinitionRegistryPostProcessors
- @Configuration imported via ImportBeanDefinitionRegistrar is not processed as configuration [SPR-11430] #16056
@Configurationimported via ImportBeanDefinitionRegistrar is not processed as configuration - @Configuration imported via @ImportResource is not processed [SPR-11723] #16345
@Configurationimported via@ImportResourceis not processed