springmvc中为什么要添加注解驱动?


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中配置,
因此会添加这个驱动


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM