Original: http://selppay-gmail-com.iteye.com/blog/763263
1. Spring Bean defination
In general, we define and apply beans using bean IDs, but today I have this definition
XML code
- <bean id = "writeservice" class = "Aserviceimp, Bserviceimp, cserviceimp"
- name = "Aservice, bservice, cservice" Init-method = "init">
- <property name = "InterfaceName">
- <value>baseservice></value>
- </Property>
- ............
- </Bean>
Such a definition first indicates aservice, bservice, Cservice implements interface Baseservice
When injected with the spring IOC, you can use either the ID writeservice or the name Aservice/bservice/cservice
What is the difference between Bean ID and bean name?
Google and Baidu can not find the answer I want, and finally in spring's official web found the following explanation, I understand that: the definition of bean name is legal, but a bean name can not be unique to represent a bean, That is, multiple beans can have the same bean name, but the bean ID is the only one that identifies a bean, so we should try to avoid using the bean name to refer to the bean.
Original explanation:
For a fallback match, the bean name is considered as a default qualifier value. This means, the bean is defined with an ID "main" instead of the nested qualifier element, leading to the same mat Ching result. However, note that and this can used to refer to specific beans by name, @Autowired was fundamentally about TYPE-DRIV En injection with optional semantic qualifiers. This means so qualifier values, even when using the beans name fallback, always has narrowing semantics within the set O F type matches; They does not semantically express a reference to a unique bean ID. Good qualifier values would be "main" or "EMEA" or "persistent", expressing characteristics of a specific component-inde Pendent from the bean ID (which is auto-generated in case of a anonymous bean definition like the one above).
The difference between the spring Bean ID and the bean name