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>
|
转载开涛博客
转载于:https://www.cnblogs.com/zyzcj/p/5286190.html
Spring 和SpringMVC 的父子容器关系相关推荐
- Spring和SpringMVC的父子容器关系
容器 在Spring整体框架的核心概念中,容器是核心思想 就是用来管理Bean的整个生命周期的 在一个项目中,容器不一定只有一个 Spring中可以包括多个容器,而且,容器有上下层关系 一个项目中引入 ...
- Spring和SpringMVC父子容器关系初窥
一.背景 最近由于项目的包扫描出现了问题,在解决问题的过程中,偶然发现了Spring和SpringMVC是有父子容器关系的,而且正是因为这个才往往会出现包扫描的问题,我们在此来分析和理解Spring和 ...
- 探究Spring和SpringMVC父子容器关系
兄弟萌,相信有很多人想不到 Spring 和 SpringMVC 是父子容器吧,^ - ^,下面我们来一探究竟. 一般做 SSM 框架项目时,扫描 @Controller 注解类的对象是在 Sprin ...
- 热门框架系列 (二) -- SpringMvc的父子容器,SpringBoot是否有父子容器?
@TOC# 热门框架系列 记录在程序走的每一步___auth:huf 从新的篇章开始;篇章阅读需要先关注; 因为笔者想参与技术文章的评选.;需要一定的粉丝量; 粉丝量达到一定数量.所有文章阅读限制将会 ...
- Spring和springmvc两个容器的关系
1.如果子容器(SpringMVC)的包扫描时,把service类扫进去SpringMVC中,会出现配置的事务不生效.因为这样controller会先调用子容器里的service,而子容器里的serv ...
- 理解spring父子容器
一.Spring和SpringMVC的父子容器关系 一般来说,我们在整合Spring和SpringMVC这两个框架中,web.xml会这样写到: <!-- 加载spring容器 --> & ...
- Spring父子容器的关系分析--用实例说话
Spring中父子容器的实现实例Spring的父子容器可以通过ConfigurableApplicationContext或ConfigurableBeanFactory来实现,这两个接口中分别有se ...
- boot spring 没有父子容器_Spring 系列(二):Spring MVC的父子容器
1.背景 在使用Spring MVC时候大部分同学都会定义两个配置文件,一个是Spring的配置文件spring.xml,另一个是Spring MVC的配置文件spring-mvc.xml. 在这里给 ...
- 【Spring(八)】父子容器
Spring的容器具可以具有父子关系.具体含义就是:如果两个容器具有父子关系,那么在查找bean时,会先从子容器中查找,如果没有就查找父容器.但是父容器不能查找子容器的bean. 这个特性有什么意义? ...
- spring的父子容器
在创建ssm项目工程时,经常需要读取properties资源配置文件,传统的方法当然可以. 但是spring提供了更简便的方法,@value注解. 在page.properties文件中,配置分页信息 ...
最新文章
- java race condition_java多线程(一)Race Condition现象及产生的原因
- ------ 比较二位数组大小-----
- 变分自编码器系列:VAE + BN = 更好的VAE
- websocket使用
- 五年级信息技术上册教案计算机主机探秘,第1课信息与信息技术探秘教案
- 计算机应用基础山东大学,山东大学计算机应用基础
- eclipse配置tomcat,并部署一个Java web项目到tomcat上
- SqlServer2008修改编辑前200行
- atitit. web 在线文件管理器最佳实践(1)--- elFinder 的使用流程解决之道 。打开浏览服务器文件夹java .net php
- 电商数据分析方法和指标整理
- 在LaTeX中添加Visio绘图
- jQuery 身份证验证
- 电力拖动自动控制系统复习(四)
- C/C++ isalpha、isalnum、islower、isupper函数详解
- 证券市场的法律法规体系
- 高斯win和linux,微软雅黑在 win 和 Linux 下安装使用的对比
- python实用程序育儿法下载_Python机器学习经典实例
- NA公链(Nirvana)NAC公链独步公链江湖
- 留住幸福的办法是不断创造幸福
- 利用GitHub制作免费个人主页
热门文章
- fiddler手机抓包 443
- gogs仓库代码拉取不需要用户账号验证问题
- Layui layer.open 弹窗 关闭按钮不见了?
- PHP中的数组(拆分与合并)
- jk-fourm.php,JK车头灯与我的新年期望(已更新完毕)
- relocation R_X86_64_PC32 against symbol can not be used when making a shared object recompile with
- SHELL下把一个文件附加到另外一个文件,注意编码问题
- 管理:权力是用来完成责任的
- WINDOWS获得当前执行程序路径的办法
- 没有别的厂家生产薯片?