在spring的配置文件中,如果我們一個一個地配置bean會非常麻煩,因此我們可以使用注解的方式
使用@Autowired注解,必須事先在Spring容器中聲明AutowiredAnnotationBeanPostProcessor的Bean:
使用 @Required注解,就必須聲明RequiredAnnotationBeanPostProcessor的Bean
類似地,使用@Resource、@PostConstruct、@PreDestroy等注解就必須聲明 CommonAnnotationBeanPostProcessor;
使用@PersistenceContext注解,就必須聲明 PersistenceAnnotationBeanPostProcessor的Bean。
這樣配置未免繁瑣,難看..因此Spring為解決這個問題,提供了和很方便一次性解決方案
就是在spring的配置文件中國配置
<context:annotation-config></context:annotation-config>
另外,我們在配置注解的時候也會配置包掃面,自動掃面配置的包下面的javabean,實現自動注入
<context:component-scan base-package="com.crm"></context:component-scan>
另外使用context命名空間必須在beans中聲明context命名空間