<mvc:annotation-driven/>、<context:component-scan base-package=""/>、<context:annotation-config/>的用法
2016-03-29 14:19
459 查看
在Spring中<context:annotation-config/>表示在自动装配时,我们可以使用注解的方式 例如:@Autowired,但是此时在xml文件中仍需要bean配置,只不过此时代替了bean的property
<context:component-scan base-package=""/>表示扫描指定的包,将注解的类注册为spring容器中的bean,那么此时我们在xml文件中就不需要定义bean,实现xml文件的零配置
<mvc:annotation-driven/>表示在SpringMVC中注册了DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,表示为@controller、@requestMapping做好准备工作,但是
此时被注解的bean并没有被加入到spring容器中,此时需要用<context:component-scan base-package=""/>扫描并注册bean,因此我们在SpringMVC中出现将<mvc:annotation-driven/>、<context:component-scan
base-package=""/>一起使用。
<context:component-scan base-package=""/>表示扫描指定的包,将注解的类注册为spring容器中的bean,那么此时我们在xml文件中就不需要定义bean,实现xml文件的零配置
<mvc:annotation-driven/>表示在SpringMVC中注册了DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,表示为@controller、@requestMapping做好准备工作,但是
此时被注解的bean并没有被加入到spring容器中,此时需要用<context:component-scan base-package=""/>扫描并注册bean,因此我们在SpringMVC中出现将<mvc:annotation-driven/>、<context:component-scan
base-package=""/>一起使用。
相关文章推荐
- 分享微信开发Html5轻游戏中的几个坑
- Zend的MVC机制使用分析(二)
- ASP.NET MVC 4 捆绑和缩小实例介绍
- ASP.NET Mvc开发之查询数据
- ASP.NET MVC中将控制器分离到类库的实现
- asp.net实现在非MVC中使用Razor模板引擎的方法
- ASP.NET MVC中的AJAX应用
- 为ASP.NET MVC及WebApi添加路由优先级
- ASP.NET MVC中图表控件的使用方法
- ASP.NET MVC的四种验证编程方式
- 仅30行代码实现Javascript中的MVC
- ASP.NET MVC 3仿Server.Transfer效果的实现方法
- 如何在MVC应用程序中使用Jquery
- ASP.NET MVC小结之基础篇(二)
- ASP.NET小结之MVC, MVP, MVVM比较以及区别(一)
- Asp.net实现MVC处理文件的上传下载功能实例教程
- ASP.NET MVC小结之基础篇(一)
- 12种JavaScript常用的MVC框架比较分析
- 浅析Asp.net MVC 中Ajax的使用
- JSP使用MVC模式完成删除和修改功能实例详解