Spring的注解开发
注解:
- @Qualifier(value = "xxx")去配合使用,指定一个唯一的id对象
- @Nullable 字段标志的注解,说明这个字段可以为null
-
@Autowire在属性上个使用,我们可以不用编写set方法
- @Required 应用于bean属性的setter方法
- 属性注入:
@Component
@Value("xxx")
2、衍生的注解
dao (@Repository)
service(@Service)
controller(@Controller)
3、作用域
@Scope("xxx")
注解的缺点:不是自己的类,使用不了,维护复杂
@PostConstruct 和 @PreDestroy 注释:
定义一个 bean 的安装和卸载,我们使用 init-method 和/或 destroy-method 参数简单的声明一下
浙公网安备 33010602011771号