springmvc中为什么要添加注解驱动<mvc:annotation-driven></mvc:annotation-driven>?

1  springmvc-servlet.xml中一般需要添加<mvc:annotation-driven></mvc:annotation-driven>注解驱动,但是在applicationContext.xml却不需要,

并且把springmvc-servlet.xml的配置放到applicationContext.xml中依然需要注解驱动

2  这说明了<mvc:annotation-driven></mvc:annotation-driven>注解驱动是针对controller层,而applicationContext.xml中

<context:component-scan base-package=""></context:component-scan>会自动加载驱动,但是不包括controller层的注解驱动




3  因此当有controller层的注解时就需要<mvc:annotation-driven></mvc:annotation-driven>注解驱动,而controller层一般在springmvc.xml中配置,
因此会添加这个驱动
原文地址:https://www.cnblogs.com/zxq-Study-Java/p/9911598.html