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的配置方式已经被替代,但在实际项目中,我们经常会 ...
随机推荐
- 16-underscore库(上)
第16课 underscore库 一.介绍 Underscore 是一个 JavaScript 工具库,它提供了一整套函数式编程的实用功能,但是没有扩展任何 JavaScript 内置对象.他弥补了 ...
- 【leetcode❤python】 400. Nth Digit
#-*- coding: UTF-8 -*- class Solution(object): def findNthDigit(self, n): ""&quo ...
- 运用EasyUI中datagrid读取数据库数据实现分页
1dao层 package com.hanqi.dao; import java.util.ArrayList; import java.util.List; import org.hibernate ...
- sql_树形查询
with Subqry(FID,A_TypeName,A_ParentID) as (select FID,A_TypeName,A_ParentID from tb_Appliances where ...
- Linux基础※※※※如何使用Git in Linux(二)
参考资料: 1. http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000 2. Git-简 ...
- Flex Excel下载
最近做Flex里的Excel下载,用as3xls进行Excel导出后,Excel修改编辑后老出现:不能以当前格式保存...若要保存所做的更改,请单击“确定”,然后将其另存为最新的格式. 最后通过JAV ...
- C语言细节——献给初学者(二)
C语言细节——献给初学者(二) 主题 循环运用+选择判断 C语言循环有for和while/do...while: 选择判断有:if...else和switch...case 在循环中需要注意搭配br ...
- Ubuntu14.04安装redis和简单配置
1.前言 Redis是常用基于内存的Key-Value数据库,比Memcache更先进,支持多种数据结构,高效,快速.用Redis可以很轻松解决高并发的数据访问问题:做为时时监控信号处理也非常不错. ...
- go文件操作大全
参考Go官方库的文件操作分散在多个包中,比如os.ioutil包,我本来想写一篇总结性的Go文件操作的文章,却发现已经有人2015年已经写了一篇这样的文章,写的非常好,所以我翻译成了中文,强烈推荐你阅 ...
- 能源项目xml文件 -- springMVC-servlet.xml -- default-lazy-init
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w ...