A Spring bean name identifies an object registered in the Spring context. With @Bean, the method name becomes the bean name: parrot() registers a bean named "parrot". This is distinct from an attribute on the object, such as the parrot’s name "Koko". section 2.1
Choose among beans of the same type
If the context contains parrot1, parrot2, and parrot3, requesting a Parrot by type alone is ambiguous. Use the name to select one: context.getBean("parrot2", Parrot.class). section 2.1
Listing 2.13 Referring to a bean by its identifier
public class Main {
static void main() {
var context = new
AnnotationConfigApplicationContext(ProjectConfig.class);
Parrot p = context.getBean("parrot2", Parrot.class); #A
System.out.println(p.getName());
}
}See a name-based lookup selecting the parrot2 bean from the context. section 2.1
