代码改变世界

spring 注解配置

2016-05-05 11:00  taixuyingcai  阅读(234)  评论(0编辑  收藏  举报

要在spring mvc中使用注解需要在*-servlet.xml文件中添加

<mvc:annotation-driver />配置

这个配置会创建DefaultAnnotationHandlerMapping和AnnotationMethodHandlerAdapter两个bean

但是要注意,要使这个标签生效需要在xml的beans标签中添加属性

xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc     http://www.springframework.org/schema/mvc/spring-mvc.xsd"