mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Introduce ConfigurationBeanNameGenerator for @Bean-annotated methods
Includes FullyQualifiedConfigurationBeanNameGenerator implementation. Closes gh-33448
This commit is contained in:
+33
-1
@@ -67,6 +67,21 @@ class AnnotationConfigApplicationContextTests {
|
||||
assertThat(beans).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void scanAndRefreshWithFullyQualifiedBeanNames() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
context.setBeanNameGenerator(FullyQualifiedConfigurationBeanNameGenerator.INSTANCE);
|
||||
context.scan("org.springframework.context.annotation6");
|
||||
context.refresh();
|
||||
|
||||
context.getBean(ConfigForScanning.class.getName());
|
||||
context.getBean(ConfigForScanning.class.getName() + ".testBean"); // contributed by ConfigForScanning
|
||||
context.getBean(ComponentForScanning.class.getName());
|
||||
context.getBean(Jsr330NamedForScanning.class.getName());
|
||||
Map<String, Object> beans = context.getBeansWithAnnotation(Configuration.class);
|
||||
assertThat(beans).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerAndRefresh() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
@@ -74,7 +89,22 @@ class AnnotationConfigApplicationContextTests {
|
||||
context.refresh();
|
||||
|
||||
context.getBean("testBean");
|
||||
context.getBean("name");
|
||||
assertThat(context.getBean("name")).isEqualTo("foo");
|
||||
assertThat(context.getBean("prefixName")).isEqualTo("barfoo");
|
||||
Map<String, Object> beans = context.getBeansWithAnnotation(Configuration.class);
|
||||
assertThat(beans).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void registerAndRefreshWithFullyQualifiedBeanNames() {
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
context.setBeanNameGenerator(FullyQualifiedConfigurationBeanNameGenerator.INSTANCE);
|
||||
context.register(Config.class, NameConfig.class);
|
||||
context.refresh();
|
||||
|
||||
context.getBean(Config.class.getName() + ".testBean");
|
||||
assertThat(context.getBean(NameConfig.class.getName() + ".name")).isEqualTo("foo");
|
||||
assertThat(context.getBean(NameConfig.class.getName() + ".prefixName")).isEqualTo("barfoo");
|
||||
Map<String, Object> beans = context.getBeansWithAnnotation(Configuration.class);
|
||||
assertThat(beans).hasSize(2);
|
||||
}
|
||||
@@ -598,6 +628,8 @@ class AnnotationConfigApplicationContextTests {
|
||||
static class NameConfig {
|
||||
|
||||
@Bean String name() { return "foo"; }
|
||||
|
||||
@Bean(autowireCandidate = false) String prefixName() { return "bar" + name(); }
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
Reference in New Issue
Block a user