SpringBoot 源码阅读(11):@Component(@Configuration @Service @Repository @Controller)

本文深入探讨了SpringBoot中@Component、@Configuration、@Service、@Repository和@Controller注解的用途。@Component是通用组件注解,通常会使用更具体的@Service、@Repository和@Controller来替代,它们分别对应服务层、数据访问层和控制层。@Configuration标记配置类,@Service用于业务层,@Repository用于数据库操作,@Controller则定义控制器。
摘要由CSDN通过智能技术生成

@Component

该注解代表该类为Spring的组件:

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Indexed
public @interface Component {
   

	/**
	 * The value may indicate a suggestion for a logical component name,
	 * to be turned into a Spring bean in case of an autodetected component.
	 * @return the suggested component name, if any (or empty String otherwise)
	 */
	String value() default "";

}

一般不直接使用该注解,而使用:
@Configuration
@Service
@Repository
@Controller

指向更加明确的注解。

@Configuration

代表为配置类。

@Target(ElementType.TYPE
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值