spring博大精深,衍生出了兩大系列:spring boot 和sping cloud快速業務開發模式,
我們進行具體開發時,經常看到這樣以Enable*開頭的注解,如圖

?

?
等等好多例子,,,框架自帶的Enable*
@EnableAspectJAutoProxy 開啟對AspectJ自動代理的支持
@EnableAsync 開啟異步方法的支持
@EnableScheduling 開啟計劃任務的支持
@EnableWebMvc 開啟Web MVC的配置支持
@EnableConfigurationProperties 開啟對@ConfigurationProperties注解配置Bean的支持
@EnableJpaRepositories 開啟對SpringData JPA Repository的支持
@EnableTransactionManagement 開啟注解式事務的支持
@EnableCaching 開啟注解式的快取支持
看到不少網文吹噓的上天了、神乎其威,我只說一句話:它(指Enable*)只是一種注解,可參考我的博文:
Spring中@Import的三種情況 https://www.cnblogs.com/dongguangming/p/12963060.html 和
Spring Bean注冊的幾種方式https://www.cnblogs.com/dongguangming/p/12792789.html
注冊bean時的條件選擇多,導致邏輯判斷多
只要是在spring生態里搞開發,請務必搞清楚Spring Bean的生命周期程序和Bean的幾種不同注冊方式
根據各家公司的業務場景需求,也可以自己擴寫Enable功能,如

?
在專案啟動類上添加自定義注解:@EnablePrintService

?
可以把Enable*注解當成一個套路,實作方式其實是一樣的,不管有多少個應用場景(@EnableScheduling、@EnableEurekaServer、@EnableDubbo、@EnablePrintService等等),
既然是注解,那就
Spring Core Annotations:https://www.javacodegeeks.com/2019/05/spring-core-annotations.html
Spring Annotations [Quick Reference] https://javabeat.net/spring-annotations/
Spring才是核心,spring boot、spring cloud、第三方擴展都是Spring的衍生品!!!
重要的是說三遍: 抓住核心看本源!!!
參考:
0 . Annotation Type EnableAutoConfiguration
https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/autoconfigure/EnableAutoConfiguration.html
1. Scheduling Tasks https://spring.io/guides/gs/scheduling-tasks/
2. Spring Job Scheduling with @Scheduled & @EnableScheduling Annotations http://websystique.com/spring/spring-job-scheduling-with-scheduled-enablescheduling-annotations/
3. @EnableScheduling in Spring https://stackoverflow.com/questions/41377002/enablescheduling-in-spring
4. Spring Annotations: Spring Cloud https://stackabuse.com/spring-annotations-spring-cloud/
5. Spring - BeanDefinitionRegistry https://anthony-dong.gitee.io/post/spring-beandefinitionregistry/
6. Grails - Java-Based Configuration
https://blog.andresteingress.com/2014/02/14/grails-java-based-spring-config.html
7. Spring Enable annotation – writing a custom Enable annotation
https://www.javacodegeeks.com/2015/04/spring-enable-annotation-writing-a-custom-enable-annotation.html
8. A Cron Expressions https://docs.oracle.com/cd/E12058_01/doc/doc.1014/e12030/cron_expressions.htm
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/179627.html
標籤:Java
