Is there anyway to specify order in which beans to be instantiated? i.e. I want specific beans to be instantiated before other beans, its like startup sequence.
I am using Spring 3.2 and annotation based declaration method.
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.
If bean A depends on bean B by defining
<property/>,@Autowiredor<constructor-arg/>then the order is forced and fixed by the Spring container. No problem here.But if you want to enforce specific order of bean creation which is not expressed via explicit dependencies feel free to use:
or better (with annotations, works also with
@BeanJava configuration):or even better… don’t use it. These constructs are a code smell and often suggest you have some nasty invisible dependency between your components.