springboot 的 Enable注解
SpringBoot中提供了很多Enable开头的注解,这些主解都是用于动态启用某些功能的。而其底层原理是使用@Import解导入一些配置类,实现Bean的动态加哦。
EnableAutoConfiguration注解 是核心注解,有configuration就是配置类注解,可以直接定义bean的。
-
SpringBoot不能直接获取在其他工程中定义的Bean
演示代码:
springboot-enable工程
/** * @ComponentScan 扫描范围:当前引导类所在包及其子包 * * com.itheima.springbootenable * com.itheima.config * //1.使用@ComponentScan扫描com.itheima.config包 * //2.可以使用@Import注解,加载类。这些类都会被Spring创建,并放入IOC容器 * //3.可以对Import注解进行封装。 */ //@ComponentScan("com.itheima.config") //@Import(UserConfig.class) @EnableUser @SpringBootApplication public class SpringbootEnableApplication { public static void main(String[] args) {