Spring Definition Name Bean
Unlike the bean class names must be unique across the whole application.
Spring definition name bean. Spring bean annotation is applied on a method to specify that it returns a bean to be managed by spring context. To match a named bean to an injection point or in other words to qualify a bean to an injection point the bean s property name at the injection point should match with the bean definition name. Fortunately you don t have to set name for each bean you create. Also this may just be the class that a factory method is called on or it may even be empty in case of a factory bean reference that a method is called on.
Spring bean name is a custom string that spring uses to identify beans. The following is a simple example of a bean method declaration. Note that this does not have to be the actual class name used at runtime in case of a child definition overriding inheriting the class name from its parent. In this case bean methods may reference other bean methods in the same class by calling them directly.
This attribute specifies the bean identifier uniquely. This definition is concise and gets to the point but misses an important thing spring ioc container. In spring the objects that form the backbone of your application and that are managed by the spring ioc container are called beans. Matching bean by using qualifier.
When javaconfig encounters such a method it will execute that method and register the return value as a bean within a beanfactory by default the bean name will be the same as the method name see bean naming for details on how to customize this behavior. Spring generates names at runtime for its. A bean is an object that is instantiated assembled and otherwise managed by a spring ioc container. To declare a bean simply annotate a method with the bean annotation.
You can t define two beans with the same name even if their types are different. To create spring application context which is capable of creating and. A child bean definition inherits configuration data from a parent definition. Spring bean annotation is usually declared in configuration classes methods.
This attribute specifies the scope of the objects created from a particular bean definition and it will be discussed in bean scopes chapter. In xmlbased configuration metadata you use the id and or name attributes to specify the bean identifier s.