spring简化 context:annotation-config, mvc:annotation-driven, context:compont-scan 区别当我们需要使用BeanPostProcessor时,直接在Spring配置文件中定义这些Bean显得比较笨拙,例如:1: 使用@Autowired注解,必须
context:annotation-config, mvc:annotation-driven, context:compont-scan 区别
当我们需要使用BeanPostProcessor时,直接在Spring配置文件中定义这些Bean显得比较笨拙,例如:
1: 使用@Autowired注解,必须事先在Spring容器中声明AutowiredAnnotationBeanPostProcessor的Bean:
2: 使用 @Required注解,就必须声明RequiredAnnotationBeanPostProcessor的Bean:
类似地,使用@Resource、@PostConstruct、@PreDestroy等注解就必须声明 CommonAnnotationBeanPostProcessor;
使用@PersistenceContext注解,就必须声明 PersistenceAnnotationBeanPostProcessor的Bean。
这样的声明未免太不优雅,而Spring为我们提供了一种极为方便注册这些BeanPostProcessor的方式,
即使用隐式地向 Spring容器注册AutowiredAnnotationBeanPostProcessor、
RequiredAnnotationBeanPostProcessor、CommonAnnotationBeanPostProcessor以及PersistenceAnnotationBeanPostProcessor这4个BeanPostProcessor。如下:
另,在我们使用注解时一般都会配置扫描包路径选项:
该配置项其实也包含了自动注入上述processor的功能,因此当使用后,即可将省去。
处理映射器和适配器
相当于注册了DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter两个bean,
配置一些messageconverter。即解决了@Controller注解的使用前提配置。
如果没有,那么所有的Controller可能就没有解析,所有当有请求时候都没有匹配的处理请求类,
就都去即default servlet处理了。添加上后,
相应的do请求被Controller处理,而静态资源因为没有相应的Controller就会被default servlet处理。
总之没有相应的Controller就会被default servlet处理就ok了。
注解式事务管理@Transactional
使用@Aspect
