What is spring injection? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What is spring injection?

2nd Jan 2017, 3:51 AM
Ashwaghosh Sadanshiv
Ashwaghosh Sadanshiv - avatar
3 Answers
+ 4
When you write this for example: @Autowired private MyService service; Then it is the responsibility of the Spring container to gain a reference to a MyService object and set it to the service variable. You can use this feature for example to change implementations without changing the code itself. Change configuration only. In newer versions of Spring you can use @Inject instead. It is a long topic, can't explained here.
3rd Jan 2017, 5:39 PM
Tamás Barta
Tamás Barta - avatar
+ 2
It is used in enterprise applications, makes it possible to use loose coupling between software components. You use interfaces and you don't have to determine in your code which implementation will be used. It can be done by an other person via configurations.
3rd Jan 2017, 6:42 PM
Tamás Barta
Tamás Barta - avatar
+ 1
but what does it offer.
3rd Jan 2017, 6:23 PM
Ashwaghosh Sadanshiv
Ashwaghosh Sadanshiv - avatar