2016年8月22日 星期一

IoC - Annotation (@Service)

At the moment, @Service serves as a specialization of @Component, allowing for implementation classes to be autodetected through classpath scanning. What this means is that you could annotate your service-layer classes with @Component, but by annotating them with @Service instead, your classes are more properly suited for processing by tools or associating with aspects, since @Service makes an ideal target for pointcuts. Of course, it is possible that @Service may carry additional semantics in the future; thus, if you are making a decision between using @Component and @Service, @Service is clearly the better choice for your service-layer.


@Component and similar annotations (@Service, @Repository, etc. )and its JSR-330 counterpart @Named allow you to declare beans that are to be picked up by autoscanning with <context:component-scan/> or @ComponentScan they register the bean definition for the classes, so they are roughly equivalent to declaring the specified beans with the <bean ... /> tag in XML. This bean types will adhere to the standard proxy creation policies.


@Component is equivalent to <bean>,
@Configuration is equivalent to <beans>.

0 意見:

張貼留言