What is a spring service annotation?
我知道
把
同样,您的组件可以充当存储库、业务逻辑类或控制器。
现在,比如说刀,
Spring进程
来自Spring文档:
1
2
3
4
5 @Target(value=TYPE)
@Retention(value=RUNTIME)
@Documented
@Component
public @interface ServiceIndicates that an annotated class is a"Service" (e.g. a business
service facade).
为什么要区分它们?
要应用编程的基本规则:您的代码应该易于阅读。
是的,您可以在任何地方使用
另一个好处是易于调试。一旦知道了错误,就不需要期望从一个组件类到另一个组件类,而是检查该类是服务、存储库还是控制器。
@服务,@controller,@repository=@component+一些更特殊的功能
单击下面的链接了解更多详细信息
在春季,@component,@repository&;@service annotations有什么区别?
The @Component annotation marks a java class as a bean so the
component-scanning mechanism of spring can pick it up and pull it into
the application context. The @Service annotation is also a
specialization of the component annotation. It doesn’t currently
provide any additional behavior over the @Component annotation, but
it’s a good idea to use @Service over @Component in service-layer
classes because it specifies intent better. Additionally, tool support
and additional behavior might rely on it in the future.
@service注释是组件注释的专用化。它目前没有在@component注释上提供任何额外的行为,但是最好在服务层类中使用@service over@component,因为它更好地指定了意图。此外,工具支持和其他行为将来可能依赖于它。