1.<context:annotation-config/>
在基于主机方式配置Spring时,Spring配置文件applicationContext.xml,你可能会见<context:annotation-config/>这样一条配置,它的作用是隐式的向Spring容器注册 AutowiredAnnotationBeanP PersistenceAnnotationBea 如果想使用@Autowired注解,需要在Spring容器中声明AutowiredAnnotationBeanP 传统的声明方式如下: <bean class= "org.springframework.beans.factory.annotation.AutowiredAnnotationBeanP 如果想使用@PersistenceContext注解,需要在Spring容器中声明PersistenceAnnotationBea 传统的声明如下: <bean class= "org.springframework.beans.factory.annotation.RequiredAnnotationBeanPo 如果想使用@Required注解,需要在Spring容器中声明RequiredAnnotationBeanPo 传统声明方式如下: <bean class= "org.springframework.beans.factory.annotation.RequiredAnnotationBeanPo 如果想使用@Resource、@ PostConstruct、@ PreDestroy等注解就要声明CommonAnnotationBeanPost 传统申明方式如下: 所以,如果按照传统声明一条一条去声明注解Bean,就会显得十分繁琐。因此如果在Spring的配置文件中事先加上<context:annotation-config/>这样一条配置的话,那么所有注解的传统声明就可以被 |
2.<context:component-scan base-package="com.xx" />
<context:component-scan/>的作用是让Bean定义注解工作起来,也就是上述传统声明方式。 它的base-package属性指定了需要扫描的类包,类包及其递归子包中所有的类都会被处理。 |
3. @Autowired
|