Reputation: 13213
There are many annotations in the Spring framework like @Component, @Service, @Repository, @Service @Resource and @Autowired etc.
What is the most appropriate way of injecting my daos in services, and my service class in the Spring Controller.
With so many annotations it is getting confusing especially with @Autowired working for all situations.
Upvotes: 1
Views: 414
Reputation: 120811
@Service
and @Repository
are just "sub-annotations" for @Component
to specify the bean a bit more (to separete Services from Repositories for more sophisticated stuff). From the point of injection this three are equal.
For injection, there are 3:
@Resource
@Inject
@Autowired
@Autowired
is the most powerful annotation, but @Resource
(JSR-250) and @Inject
(JSR-330) are standardized. — Anyway if you not plan to reuse your application in a non-Spring environment, then I would not pay to many attention to this concern.
Upvotes: 2
Reputation: 813
I prefer to avoid annotations, especially if they start getting confusing. Nothing wrong with good old getter and setters in this case. Just gotta wire the bean on your own, which isn't so difficult that annotations are necessary.
Upvotes: 0
Reputation: 6811
See Annotation based configuration in Spring, best Spring Annotation
tutorial for me.
Upvotes: 2