spring
linmsen 2020-08-01 spring
# spring注解
# 注入
https://zhuanlan.zhihu.com/p/44179797
@Value 注入int、float、String等基本数据类型,只能标注在成员变量、setter方法上。
@Autowired 按类型自动装配,可标注在成员变量(官方不推荐)、构造方法、setter方法上。
@Qualifier 按名称自动装配,需要和@Autowired搭配使用,只能标注在成员变量(官方不推荐)、setter方法上。
@Resource 按名称或类型自动装配,需要第三方包 javax.annotation.jar 的支持,只能标注在成员变量、setter方法上。
1
2
3
4
5
2
3
4
5
# 模式注解
@Repository
@Component
@Controller
@Configuration
全部是@Component的派生注解
1
2
3
4
5
2
3
4
5
装配类
@ImportResource
@Import
@ComponmentScan
1
2
3
2
3
# 循环依赖
@Lazy
1
# 构造器
如果构造器需要用到注入的参数字段,需要加
@PostConstruct
1
# 元注解
@Target 注解用在哪里
@Retention
@Documented
@Inherited
@Repeatable
1
2
3
4
5
2
3
4
5
# 派生性
注解描述注解
# @Enable模块驱动
# @Configuration驱动
# 条件注解
@C