Seems,that very basic question.
Anyway can’t get the meaning of next definition from Spring tutorials – “bean X is injected into bean Y” .
Does it mean composition relation between classes(when one bean has reference to another)? Or it’s something more?
Thank you for answer or reference with explanation.
Yes, The question is very basic. Dependency Injection is one of the fundamental functionality of Spring framework. Java classes should be independent as possible, this increases the flexibility to reuse the classes and testing classes independently. For this decoupling, the dependency of one class to another class should be injected into them by a third party rather than the class itself creates the other object.
In Spring framework, a light weight container called Spring core container performs dependency injection. ie this container will inject required dependencies in required objects.
In Web application, there will be a controller class, a service class, a dao class etc. In controller class there will be reference to service class, in service class there will be a reference to dao class. When using spring, the dependencies can be configured using XML or annotation or Java config.
Take the scenario between controller class (MyController.java) and service class (MyService.java),
In the xml configuration file, we define the dependency as follows,
When controller bean is created, the dependency will be resolved by the core container.