I am working on a Spring MVC project where I am dealing with different types of services,Repositories i.e classes annotated with @Service
and @Repository
. I am confused with a couple of questions:
When to use
@AutoWired
annotation?I have seen various repositories using this:
CourseRepository crepo=new CourseRepository();
and I have seen this also
@AutoWired private CourseRepository crepo;
Which one of the above options should be used to get an instance of repository in Service class?
Can I use
@AutoWired
for classes which are not annotated with@Repository
or@Service
?
I am a beginner in this java world.Any help will be highly appreciated. Thanks