Spring的注解开发

注解

  1. @Qualifier(value = "xxx")去配合使用,指定一个唯一的id对象
  2. @Nullable 字段标志的注解,说明这个字段可以为null
  3. @Autowire在属性上个使用,我们可以不用编写set方法

  4. @Required 应用于bean属性的setter方法

 

 

  1. 属性注入:

    @Component

    @Value("xxx")

  2、衍生的注解

    dao (@Repository)

    service(@Service)

    controller(@Controller)

  3、作用域

    @Scope("xxx")

注解的缺点:不是自己的类,使用不了,维护复杂

 

 

@PostConstruct 和 @PreDestroy 注释:

  定义一个 bean 的安装和卸载,我们使用 init-method 和/或 destroy-method 参数简单的声明一下

posted @ 2022-01-06 10:01  JunLiu1  阅读(26)  评论(0)    收藏  举报