Detect factory method annotations in getBeanNamesForAnnotation and co
As of 5.2, ListableBeanFactory.findAnnotationOnBean and its retrieval companions getBeanNamesForAnnotation and getBeansWithAnnotation detect annotations on @Bean methods as well. Closes gh-22541
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -129,6 +129,16 @@ public class BeanMethodQualificationTests {
|
||||
assertThat(pojo.testBean.getName(), equalTo("interesting"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanNamesForAnnotation() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(StandardConfig.class);
|
||||
assertArrayEquals(new String[] {"beanMethodQualificationTests.StandardConfig"},
|
||||
ctx.getBeanNamesForAnnotation(Configuration.class));
|
||||
assertArrayEquals(new String[] {}, ctx.getBeanNamesForAnnotation(Scope.class));
|
||||
assertArrayEquals(new String[] {"testBean1"}, ctx.getBeanNamesForAnnotation(Lazy.class));
|
||||
assertArrayEquals(new String[] {"testBean2"}, ctx.getBeanNamesForAnnotation(Boring.class));
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class StandardConfig {
|
||||
|
||||
Reference in New Issue
Block a user