赞
踩
文中部分图片来源为 动力节点-王鹤老师的Spring Boot3.0 视频讲解中。
自动配置:从类路径中,搜索相关的 jar,根据 jar 的内容,尝试创建所需的对象。例如,如果有 MyBatis .jar,Spring Boot 会尝试创建 DataSource(根据配置文件中的url,username,password)连接数据库。还需要创建 SqlSessionFactory,Dao 接口的代理对象。这些内容不需要开发人员写一行代码,就能使用 MyBatis 框架了。


xxx.imports 文件是自动配置类列表。 ====> 说明有哪些自动配置类。
xxxAutoConfiguration 是自动配置类。====> @EnableConfigurationProperties({xxxProperties.class}) 将指定的绑定Bean注入到容器中。
xxxProperties 是绑定Bean。 ====> @ConfigurationProperties(prefix = “xxxx”) 说明该类是一个绑定Bean。
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@AutoConfigurationPackage
@Import(AutoConfigurationImportSelector.class)
public @interface EnableAutoConfiguration {
String ENABLED_OVERRIDE_PROPERTY = "spring.boot.enableautoconfiguration";
Class<?>[] exclude() default {};
String[] excludeName() default {};
}
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Import {
Class<?>[] value();
}



Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。