关于应用上下文
2018-02-05 00:00
190 查看
1、ApplicationContext hierarchies in spring:
An ApplicationContext cannot have more than 1 parent ApplicationContext.
When a given ApplicationContext cannot resolve a bean, it will pass on the resolution request to its parent.
The parent of an ApplicationContext is specified in its constructor.
The classic use-case for this is when you have multiple Spring DispatcherServlet within a single webapp, with each of these servlets having their own application context.
Each Spring MVC webapp has one root application context and one servlet application context for each DispatcherServlet. The root application context is the parent of each servlet application context. Beans defined in "contextConfigLocation" (context-param in web.xml) are loaded into root application context. Beans in <servlet-name>-servlet.xml are loaded into servlet application context.
2、ApplicationContext ServletContext
spring中WebApplicationContext、DispatcherServlet与web容器的ServletContext关系梳理
SpringMVC自动扫描@Controller注解的bean
补充:在springmvc 和 spring 都有注解扫描的前提下,能不能将事务配置在Controller层?
答案:是不能的,因为事务管理器是配置在spring容器中的,如果将事务配置在Controller层的话,spring容器就访问不了springmvc子容器,进而无法访问到事务对象。进而导致事务失效。
3、ApplicationContextAware ServletContextAware
An ApplicationContext cannot have more than 1 parent ApplicationContext.
When a given ApplicationContext cannot resolve a bean, it will pass on the resolution request to its parent.
The parent of an ApplicationContext is specified in its constructor.
The classic use-case for this is when you have multiple Spring DispatcherServlet within a single webapp, with each of these servlets having their own application context.
Each Spring MVC webapp has one root application context and one servlet application context for each DispatcherServlet. The root application context is the parent of each servlet application context. Beans defined in "contextConfigLocation" (context-param in web.xml) are loaded into root application context. Beans in <servlet-name>-servlet.xml are loaded into servlet application context.
2、ApplicationContext ServletContext
spring中WebApplicationContext、DispatcherServlet与web容器的ServletContext关系梳理
SpringMVC自动扫描@Controller注解的bean
补充:在springmvc 和 spring 都有注解扫描的前提下,能不能将事务配置在Controller层?
答案:是不能的,因为事务管理器是配置在spring容器中的,如果将事务配置在Controller层的话,spring容器就访问不了springmvc子容器,进而无法访问到事务对象。进而导致事务失效。
3、ApplicationContextAware ServletContextAware
相关文章推荐
- 关于移动应用的上下文情境
- 关于javascript跨域及JSONP的原理与应用
- 关于jQuery的$.proxy()应用.
- 关于#pragma pack(1)的应用领域
- 关于VS2005中GridView的自定义分页,单选、多选、排序、自增列的简单应用
- 圣殿骑士的一篇关于WPF的培训好文,WPF应用与团队开发(转)
- 关于Silverlight的Socket 应用
- 关于SM2的应用方法
- 关于c#静态方法和实例方法的辨析和应用
- 关于Android应用的启动
- 关于java应用MD5校验文件和linux下md5Linux校验文件结果一致问题。
- Android学习札记38:关于安全退出已创建多个Activity的应用(1)
- [置顶] 关于web服务器、应用服务器、http服务器区别
- WPF 中关于 DataTemplateSelector 类的应用
- 关于IPv6的应用
- 关于OSPF路由协议在企业网络中的应用
- Loadrunner中关于C&nbsp;指针的简单应用
- 关于UIButton 在autolayout中应用中的一个问题
- 关于新闻头条上面TextView下面ViewPager第三方应用
- 关于mvc的应用思考