Reputation:
If I use @Service
on a service class, do I need to make a service class bean in my servlet xml file or do I have to do both?
Upvotes: 13
Views: 19485
Reputation: 32727
Last time I looked (Spring 2.5) @Service was a marker annotation subclassed from @Component, but with no additional behaviour. Which means that beans tagged with @Service become candidates for auto detection if you are using annotation-based configuration via classpath scanning.
As per the docs, the intention is that this annotation might include service layer specific functionality in future Spring releases. It can also act as an AOP point cut for all of your service layer components.
Upvotes: 5
Reputation: 497
You don't have to declare a bean in your context file if you:
1) Annotate the class with:
@Component, @Service, @Controller or @Repository
2) Include the context:component-scan element in your context file like this:
<context:component-scan base-package="your.package" />
Hope that helps.
Upvotes: 14