-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Closed
Description
Andy Wilkinson opened SPR-16839 and commented
The problem's hopefully illustrated by the following two tests:
package com.example.demo;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
public class ImportVersusDirectRegistrationTests {
@Test
public void thingIsAvailableWhenOuterConfigurationIsRegisteredDirectly() {
try (AnnotationConfigApplicationContext directRegistration = new AnnotationConfigApplicationContext()) {
directRegistration.register(AccidentalLiteConfiguration.class);
directRegistration.refresh();
directRegistration.getBean(Thing.class);
}
}
@Test
public void thingIsAvailableWhenOuterConfigurationIsImported() {
try (AnnotationConfigApplicationContext viaImport = new AnnotationConfigApplicationContext()) {
viaImport.register(Importer.class);
viaImport.refresh();
viaImport.getBean(Thing.class);
}
}
}
@Import(AccidentalLiteConfiguration.class)
class Importer {
}
class AccidentalLiteConfiguration {
@Configuration
class InnerConfiguration {
@Bean
public Thing thing() {
return new Thing();
}
}
}
class Thing {
}thingIsAvailableWhenOuterConfigurationIsImported will pass but thingIsAvailableWhenOuterConfigurationIsRegisteredDirectly will fail. This appears to be because member classes of a lite configuration class are only processed when the lite configuration class has been imported. They are not processed when it's been registered directly with the application context.
Affects: 5.0.6
Reference URL: spring-projects/spring-boot#13129
Issue Links:
- Add bean definition attribute for ConfigurationClassPostProcessor to skip "lite" bean detection [SPR-17412] #21945 Add bean definition attribute for ConfigurationClassPostProcessor to skip "lite" bean detection
- Revisit @Bean introspection between @Configuration classes and 'lite' beans [SPR-17206] #21739 Revisit
@Beanintrospection between@Configurationclasses and 'lite' beans
Referenced from: commits spring-projects/spring-boot@5cc1a83
0 votes, 5 watchers
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
type: enhancementA general enhancementA general enhancement