Spring注解到底有哪些?

一.注解定义Bean

@component(描述Spring框架中的bean)

下面三个注解与component等效
@Repository(用于对DAO实现类进行标注)
@Service(用于对业务类进行标注)
@Controller(用于对控制类进行标注)

这三个注解是为了让标注类本身的作用清晰,Spring会在后续版本进行增强



二.Spring属性注入(注解方式)

 @Autowired():自动注入
 @Autowired(required=true):找到匹配的Bean
 @Qualifier():可指定Bean的名称
 @Resource()和Autowired*()功能相似



三.其他注入

@PostConStruct():初始化
@PreDestory():销毁
@Scope()指定作用域

猜你喜欢

转载自blog.csdn.net/weixin_43927892/article/details/104385101