I know what bean alias means in spring. But I want to know the use cases for making use of alias. Why would somebody want to refer a bean using alias name instead of its name?
Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A usage I’ve seen is the following: you have two instances of a given interface (
SomeBean): one for environment A, and one for environment B. So you define two beans: one named “someBeanForA”, and the other one named “someBeanForB”.The beans where this SomeBean must be injected don’t know which one they must use: it depends on the environment. So they use an alias:
When deploying to the environment A, the alias in the XML file points to someBeanA. When deploying to the environment B, the alias in the XML file points to someBeanB.