您的位置:首页 > 其它

关于应用上下文

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: