What is @Service in Spring MVC
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?
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.
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.
精彩评论