1 <context:annotation-config />
作用:注册AutowiredAnnotationBeanP
注册这4个
2 <context:component-scan base-package=""/>:包含了context:annotation-config 的功能,同时能指定扫描路径。因此当使用 <context:component-scan/> 后,除非需要使用PersistenceAnnotationBeanPostProcessor和equiredAnnotationBeanPostProcessor两个Processor的功能(例如JPA等)否则就可以将 <context:annotation-config/> 移除了。
3 <mvc:annotation-driven />
DefaultAnnotationHandlerMapping
用来解析Spring MVC里面的annotation对应的Controller,也就是通过这个类,给annotation设置映射关系,如@RequestMapping等,主要方法determineUrlsForHandlerMethods(Class<?> handlerType, final boolean hasTypeLevelMapping)
AnnotationMethodHandlerAdapter
对Annotation设置的方法进行处理的类,通过此类,解析annotation设置的类的处理,也就是有请求时,通过此类,可以调用annotation设置controller的方法,主要处理方法,handle(HttpServletRequest req, HttpServletResponse resp, Object handler)。
<mvc:annotation-driven/>相当于注册了DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter两个bean,配置一些messageconverter。即解决了@Controller注解的使用前提配置。