I am very new to spring boot and I am trying to grasp the concept of it. Now I came across @Autowired in it. I understood pretty much about it.
Like, when you write @Autowired, things happen in two passes and in the second pass spring injects beans.
Now, I have this example;
Class Abc {
@Autowired
private Xyz xyz;
PSVM(String...z) {
xyz.hello();
}
}
Import basically imports the code into the file.
So,
Import com.tilak.Xyz;
Class Abc {
private Xyz xyz;
PSVM(String...z) {
xyz = new Xyz();
xyz.hello();
}
}
Why should/ shouldn't I go with the latter one?
Is there any advantage in doing the first one? Where should I use the first one and where should I use the second one?