Spring container will traverse the DAG (directed acyclic graph) of dependencies and will validate the configuration as much as possible without creating instances of the beans. The exceptions here are singleton-scoped and pre-instanciated beans, which are created on container creation. You can modify this behavior by adding lazy-init="true"
property to the bean definition.
Only when the bean is requested in your code, it will get actually created created with all of its dependencies created first (and their dependencies if so needed) traversing the dependencies graph (DAG) all the way to the deepest dependencies.
Another case is when beans are defined later with the exact same name. These override the beans defined earlier - so if you have mocks for some of the beans, just define it after the core application beans have been loaded up.
You can add also add property depends-on="list,of,comma,separated,beanIDs"
to your bean config to guide the container, when some dependencies are not explicit.
When configuring using annotated classes, you can also add @Order(N)
where lower N
s get higher priority order used mostly to influence the order of beans being added to a collection, where order matters.