I\'m a little confused as to how the inversion of control (IoC
) works in Spring
.
Say I have a service class called UserServic
The whole concept of inversion of control means you are free from a chore to instantiate objects manually and provide all necessary dependencies.
When you annotate class with appropriate annotation (e.g. @Service
) Spring will automatically instantiate object for you. If you are not familiar with annotations you can also use XML file instead. However, it's not a bad idea to instantiate classes manually (with the new
keyword) in unit tests when you don't want to load the whole spring context.