Spring中的@ Component,@ Repository和@Service批注有什么区别?

问题:

Can [@Component](https://my.oschina.net/u/3907912) , [@Repository](https://my.oschina.net/u/3055569) and [@Service](https://my.oschina.net/service) annotations be used interchangeably in Spring or do they provide any particular functionality besides acting as a notation device? [@Repository](https://my.oschina.net/u/3055569) [@Component](https://my.oschina.net/u/3907912)@Repository@Service批注可以在Spring中互换使用吗,或者除了充当注解设备外,它们还提供任何特定功能吗?

In other words, if I have a Service class and I change the annotation from @Service to @Component , will it still behave the same way? 换句话说,如果我有一个Service类,并且将注释从@Service更改为@Component ,它的行为是否仍将相同?

Or does the annotation also influence the behavior and functionality of the class? 还是注释也会影响类的行为和功能?


解决方案:

参考一: https://stackoom.com/question/SeD2/Spring中的-Component-Repository和-Service批注有什么区别
参考二: https://oldbug.net/q/SeD2/What-s-the-difference-between-Component-Repository-Service-annotations-in-Spring

点赞
收藏

评论区

加载中...

相关推荐

@Repository、@Service、@Controller 和 @Component

@Repository、@Service、@Controller(https://my.oschina.net/u/1774615)和@Component将类标识为Beanspring自2.0版本开始,陆续引入了一些注解用于简化Spring的开发。@Repository注解便属于最先引入的一批,它用于将数据访问层(DAO层)的类

Spring注解校验1

Spring字段校验的注解说明限制说明@Null(https://my.oschina.net/u/561366)限制只能为null@NotNull(https://my.oschina.net/notnull)限制必须不为null@AssertFalse(https://my.oschina.net/u/24

Spring的@Import 注解的作用与用法

@Import注解@Import(https://my.oschina.net/u/3201731)是Spring基于Java注解配置的主要组成部分。@Import(https://my.oschina.net/u/3201731)注解提供了@Bean(https://my.oschina.net/bean

From表单提交的几种方式

<body<formaction"https://my.oschina.net/u/3285916"method"get"name"formOne"id"formId"name:<inputtype"text"name"name"pwd:<inputtyp

@Enable驱动逻辑

这个系列分为5篇1\.@Component,@Service等注解是如何被解析的(https://my.oschina.net/floor/blog/4325651)2\.@Enable驱动原理(https://my.oschina.net/floor/blog/4333081)3\.@EnableAutoConfiguratio

@EnableAutoConfiguration处理逻辑

这个系列分为5篇1\.@Component,@Service等注解是如何被解析的(http://my.oschina.net/u/3907912)2\.@Enable驱动原理(https://my.oschina.net/floor/blog/4333081)3\.@EnableAutoConfiguration处理逻辑(htt