0

Even if JVM is there, how it is allowing Spring Container to come into the play while executing the Spring Application?

When we have configured JVM then how still Spring Container is taking responsibility to execute the objects?

  • does after running main method of Spring.Application, JVM hand over the execution of objects to Container – Sanjiv Kumar May 14 '23 at 19:15
  • 1
    The Spring framework, like all Java code (ignoring things like Android and GraalVM native images), is executed _by the JVM_. So, no, the JVM does not "hand over" execution to Spring. – Slaw May 14 '23 at 19:28
  • The Spring container is executed like any other Java code: as Java code, by the JVM. – knittl May 14 '23 at 19:31
  • There's nothing particularly special about Spring; it's complicated, but not particularly special. You call the framework's entry point and that causes code to execute, like normal. It's just that said code does stuff like scan the class-path for annotations, set up network connections, set up the handling of incoming connections, initialize "sub" frameworks (e.g., JPA) as needed, instantiate objects "for you" as needed, and so on. But that's all just Java code, same as you write in your programs. – Slaw May 14 '23 at 19:36
  • Please provide enough code so others can better understand or reproduce the problem. – Community May 15 '23 at 00:22
  • but after all dependency injection is done by container and not by JVM.So, its like container working like JVM – Sanjiv Kumar May 15 '23 at 06:12
  • Perhaps the piece you're missing is what's called [reflection](https://stackoverflow.com/q/37628/6395627). Reflection can be used to instantiate and invoke code unknown at compile-time. Spring uses reflection, and other tools, to do what it does. Some of those other tools may or may not include compile-time and/or run-time annotation processing, instrumentation, proxies, run-time generation of classes, and so on. But all this code is still executed by the JVM; Spring is not "becoming" the JVM in any way. – Slaw May 15 '23 at 07:15
  • See packages like `java.lang`, `java.lang.annotation`, `java.lang.reflect`, `java.lang.invoke` and `java.lang.instrument`. All in the standard library. – Slaw May 15 '23 at 07:20

0 Answers0