How does JVM and spring container work together during objs or beans creation?

789 Views Asked by At

Spring container creates Beans by creating a DAG first and then instantiates the non-dependent beans before creating any beans that are dependent on other beans. This is fine and understood. Any beans that is are dependent on regular java objects / pojo's could be supplied by JVM classloader mechanism and that fine too.

But any java object that's dependent on a bean is what causing me to understand this interleaved mechanism bit more in depth.

  1. in simple case - JVM can wait for the spring container to finish its bean creation process and then JVM can create any java objs it has to.

and

  1. for interleaved beans and java objs: they both (jvm and spring container) will create beans and java objs in an interleaved fashion as required. I think of this because, when a bean can have a ref to regular java obj and a in turn a java obj could have a bean as dependency.

So, Just to clarify - does Spring Container and JVM create beans and obj's in interleaved fashion.

(This is a Q to understand the working of Spring Container along side JVM, this can not be specific to a class or seceniro or use case, so please don't mark this question as lacking somthing like specifics or use case or somthing else -- Thanks for understanding.)

Edit following @BoristheSpider comment:
Take some spring bean. Spring container will try to create this bean. Now, say, this bean is depended on a pojo. So now, how is this pojo created. Is it created by Spring Container directly or by delegating it to the respective JVM classloader (bootstrap or ext or application). I am thinking it will delegate it to corresponding JVM classloader. someone can clarify this.
NEXT - when JVM has to create a pojo which is dependent on bean how does it know about the bean. So JVM and Spring Container has to care about one and other. How to they work hand-in-hand is what I am trying to uderstand.

0

There are 0 best solutions below