Spring常用注解
一、定时任务 @Scheduled @EnableScheduling
二、扫描组件 @ComponentScan
三、组件 @component
1、@controller 控制器(注入服务)
2、@service 服务(注入dao)
3、@repository dao(实现dao访问)
4、@component (把普通pojo实例化到spring容器中,相当于配置文件中的<bean id="" class=""/>)
四、缓存 @EnableCaching @Cacheable
Spring Cache 使用 ---@EnableCaching @Cacheable 注解
五、区分实现类 @Qualifier
六、配置 @Configuration
七、 @PostConstruct 、@Autowired和Construct 顺序
结论: 构造方法 > @Autowired > @PostConstruct ???待验证
参考网址:https://blog.csdn.net/qq_27256783/article/details/98478181
八、@Configuration(proxyBeanMethods = false) 详解
Full(proxyBeanMethods = true) :proxyBeanMethods参数设置为true时即为:Full 全模式。 该模式下注入容器中的同一个组件无论被取出多少次都是同一个bean实例,即单实例对象,在该模式下SpringBoot每次启动都会判断检查容器中是否存在该组件
Lite(proxyBeanMethods = false):proxyBeanMethods参数设置为false时即为:Lite 轻量级模式。该模式下注入容器中的同一个组件无论被取出多少次都是不同的bean实例,直接返回新实例对象,在该模式下SpringBoot每次启动会跳过检查容器中是否存在该组件。Spring Boot在2.2.0版本(依赖于Spring 5.2.0)起就把它的所有的自动配置类的此属性改为了false,即@Configuration(proxyBeanMethods = false),提高Spring启动速度。
原文链接:https://blog.csdn.net/leesinbad/article/details/132612533
九、@ConditionalOnMissingClass
在 Spring Boot 中,@ConditionalOnMissingClass 注解用来判断指定的类是否在 classpath 中存在:
-
如果你指定的类在 classpath 中存在,则匹配失败;
-
如果你指定的类在 classpath 中不存在,则匹配成功;