Spring 和SpringMVC 的父子容器关系
1
|
<context:component-scan base- package =“com.test" /> |
HandlerMapping,是SpringMVC中用来处理Request请求URL到具体Controller的,其自身也分成很多种类;
HandlerAdapter,是SpringMVC中用来处理具体请求映射到具体方法的,其自身也分很多种类;
@RequestMapping这个注解的主要目的就是对具体的Controller和方法进行注册,以方便HandlerMapping用来处理请求的映射。但是@RequestMapping需要结合<mvc:annotation-driven />使用才能生效。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
protected void initHandlerMethods() { if (logger.isDebugEnabled()) { logger.debug( "Looking for request mappings in application context: " + getApplicationContext()); } String[] beanNames = ( this .detectHandlerMethodsInAncestorContexts ? BeanFactoryUtils.beanNamesForTypeIncludingAncestors(getApplicationContext(), Object. class ) : getApplicationContext().getBeanNamesForType(Object. class )); for (String beanName : beanNames) { if (isHandler(getApplicationContext().getType(beanName))){ detectHandlerMethods(beanName); } } handlerMethodsInitialized(getHandlerMethods()); } |
1
2
3
|
protected boolean isHandler(Class<?> beanType) { return AnnotationUtils.findAnnotation(beanType, Controller. class ) != null ; } |
1
2
3
4
5
|
<bean class = "org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" > <property name= "detectHandlerMethodsInAncestorContexts" > <value> true </value> </property> </bean> |
Spring容器配置,排除所有@controller的Bean
1
2
3
|
<context:component-scan base- package = "com.fsnip.open" > <context:exclude-filter type= "annotation" expression= "org.springframework.stereotype.Controller" /> </context:component-scan> |
SpringMVC容器配置,让其只包括@controller的Bean
1
2
3
|
<context:component-scan base- package = "com.fsnip.open" use- default -filters= "false" > <context:include-filter type= "annotation" expression= "org.springframework.stereotype.Controller" /> </context:component-scan> |
Spring 和SpringMVC 的父子容器关系的更多相关文章
- spring与springMVC的父子容器关系
背景和概述 在spring与springMVC中通过IOC可以管理bean对象,有两个配置文件可以配置ioc spring的配置文件applicationContext.xmlspringMVC的配置 ...
- spring盒springMVC整合父子容器问题:整合Spring时Service层为什么不做全局包扫描详解
整合Spring时Service层为什么不做全局包扫描详解 一.Spring和SpringMVC的父子容器关系 1.讲问题之前要先明白一个关系 一般来说,我们在整合Spring和SpringMVC这两 ...
- Spring和SpringMVC父子容器关系初窥
一.背景 最近由于项目的包扫描出现了问题,在解决问题的过程中,偶然发现了Spring和SpringMVC是有父子容器关系的,而且正是因为这个才往往会出现包扫描的问题,我们在此来分析和理解Spring和 ...
- SpringMVC与Spring的父子容器关系
问题: 在整合框架的时候有人也许会产生一个问题:能不能只配置一个扫描包加载实现类的扫描驱动,即在根目录下扫描所有的注解(@Controller.@Service.@Repository.@Compne ...
- 这一次搞懂Spring Web零xml配置原理以及父子容器关系
前言 在使用Spring和SpringMVC的老版本进行开发时,我们需要配置很多的xml文件,非常的繁琐,总是让用户自行选择配置也是非常不好的.基于约定大于配置的规定,Spring提供了很多注解帮助我 ...
- spring和springmvc父子容器关系
一般来说,我们在整合spring和SpringMVC这两个框架中,web.xml会这样写到: <!-- 加载spring容器 --> <!-- 初始化加载application.xm ...
- 03 Spring的父子容器
1.概念理解和知识铺垫 在Spring整体框架的核心概念中,容器是核心思想,就是用来管理Bean的整个生命周期的,而在一个项目中,容器不一定只有一个,Spring中可以包括多个容器,而且容器有上下层关 ...
- Spring和SpringMVC的关系
1.Spring和SpringMVC是父子容器关系. 2.Spring整体框架的核心思想是容器,用来管理bean的生命周期,而一个项目中会包含很多容器,并且它们分上下层关系,目前最常用的一个场景是在一 ...
- Spring和SpringMVC父子的容器之道---[上篇]
Spring和SpringMVC作为Bean管理容器和MVC层的默认框架,已被众多WEB应用采用,而在实际开发中,由于有了强大的注解功能,很多基于XML的配置方式已经被替代,但在实际项目中,我们经常会 ...
随机推荐
- Cron表达式简单学习
CronTriggers往往比SimpleTrigger更有用,如果您需要基于日历的概念,而非SimpleTrigger完全指定的时间间隔,复发的发射工作的时间表.CronTrigger,你可以指定触 ...
- 深入浅出设计模式——外观模式(Facade Pattern)
模式动机引入外观角色之后,用户只需要直接与外观角色交互,用户与子系统之间的复杂关系由外观角色来实现,从而降低了系统的耦合度. 模式定义外观模式(Facade Pattern):外部与一个子系统的通信必 ...
- iOS - Xcode 常用快捷键
Xcode 常用快捷键 1)文件: command + shift + n 新建项目 command + n 新建文件 command + control + n 新建空文件 command + o ...
- 【hdu5973】高精度威佐夫博弈
题意:输入a, b表示两堆石头数目,威佐夫博弈,问:先手胜负? a, b <= 1e100. 高精度.当a > b时, a = (a-b)*黄金分割比 时是先手败状态.因为a, b < ...
- 常用sql语句总结
一.连接数据库 mysql -h127.0.0.1(连接地址) -P3303(端口号) -uroot(用户名) -p123456(密码) 二.常用语句 show datebases; 查看数据库 cr ...
- 聊天界面之气泡文本cell(二)使用Autolayout
聊天界面主要是cell的动态高度计算和效率的问题,参考网上的两篇文章: 1.优化UITableViewCell高度计算的那些事 http://www.cocoachina.com/ios/20150 ...
- mongodb unclean shutdown 修复方法
启动mongodb时,提示Unclean shutdown detected mongodb,解决方法很简单 mongod --repair --dbpath D:\MongoDB\data\db
- pc, 手机全屏
全屏 1 div{ position:absolute/relative/fixed; top:0; bottom:0; left:0; right:0;} 2 <!doctype html& ...
- iOS基础篇(十七)——UIGestureRecognizer用法
UIGestureRecognizer(手势识别)在iOS 中非常重要,他极大地提高了移动设备的使用便捷性: 在3.2之前是主要使用的是由UIResponder而来的如下4种方式: - (void)t ...
- PDF 补丁丁 0.4.2.1218 测试版发布:新增拆分文档功能
新的测试版的“提取页面”功能增加了拆分文档的选项. 可按照指定的页码范围(用“:”分号分割).顶层书签或指定页数三种方式,将一个 PDF 文档拆分成多个文档. 此功能还支持多个文档批量操作. 欢迎各位 ...