Spring的applicationContext.xml的疑问解析

Spring中注解注入 context:component-scan 的使用说明

通常情况下我们在创建spring项目的时候在xml配置文件中都会配置这个标签,配置完这个标签后,spring就会去自动扫描base-package对应的路径或者该路径的子包下面的java文件,如果扫描到文件中带有@Service,@Component,@Repository,@Controller等这些注解的类,则把这些类注册为bean
注:在注解后加上例如@Component(value=”abc”)时,注册的这个类的bean的id就是adc.

Spring中context:annotation-config注解的作用

<context:annotation-config/>的作用是向Spring容器注册以下四个BeanPostProcessor:


AutowiredAnnotationBeanPostProcessor
CommonAnnotationBeanPostProcessor
PersistenceAnnotationBeanPostProcessor
RequiredAnnotationBeanPostProcessor

例如:
  如果想使用@Autowired注解,那么就必须事先在 Spring 容器中声明 AutowiredAnnotationBeanPostProcessor Bean。

原文地址:https://www.cnblogs.com/w123w/p/10643821.html