spring注解开发-IOC
1. @Configuration, @Bean @Configuration该注解就是用来告诉spring这是配置类 @Bean该注解是用来注册一个bean。类型是返回值的类型,ID默认是用方法名作为ID的;可以在注解中指定ID,@Bean("person") ApplicationContext applicationContext = new AnnotationConfigApplicationContext(MainConfig.class); //MainConfig.class是配置类 Person bean = applicationContext.getBean(Person.class); 以上注解主要是用来取代了配置文件application.xml中对bean的定义 2. @ComponentScan 该注解用于包扫描,主要是取代了下面的配置。主要扫描标记有以下注解的:@Controller、@Service、@Repository,@Component <context:component-scan base-package="com.atguigu" use-default-filters="false"></context:component-scan> 属性一:excludeFilters = Filter[]