Spring 3 bean instantiation sequence
java, spring
Solution
If bean A depends on bean B by defining `<property/>`, `@Autowired` or `<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:
<bean id="A" depends-on="B"/>
<bean id="B"/>
or better (with annotations, works also with `@Bean` Java configuration):
@Service
@DependsOn("B")
public class A {}
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.
Problem
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.