springboot @Import注解
@Enable"底层依赖于@lmport注解导入一些类,使用@lmport导入的类会被Springh载到OC容器中。而@mport提供4中用法:
Import4中用法:
-
- 导入Bean
-
- 导入配置类
-
- 导入ImportSelector的实现类。
-
- 导入ImportBeanDefinitionRegistrar实现类
@SpringBootApplication
public class SpringbootEnableApplication {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(SpringbootEnableApplication.class, args);
/*//获取Bean
Object user = context.getBean("user");
System.out.println(user);*/
/*User user = context.getBean(User.class);
System.out.println(user);
Role role = context.getBean(Role.class);
System.out.println(role);*