`

spring ContextLoaderListener 和 DispatcherServlet 的加载问题

阅读更多

http://www.iteye.com/problems/98179

 

在spring mvc中@Controller注解的bean必须由DispatcherServlet初始化的children webApplicationContext来管理,在DispatcherServlet初始化的context中会扫描当前容器所有的bean实例,根据类级别以及方法级别的映射信息注解组装成对应的HandleMappering信息,但是ContextLoaderListener是不具备这个功能的,所以你的A bean实例有问题。 
另外,最好使用DispatcherServlet去扫描@Controller注解的bean,而servie bean使用COntextLoaderListener scan(web层controlller配置文件最好独立于其他业务bean配置文件)

 

 

你可以这么理解,由DispatcherServlet加载相当于在ContextLoaderListener加载的基础上增加了controller的处理,所以DispatcherServlet加载的controller和bean都好用,ContextLoaderListener加载的bean好用而controller不好用. 

分享到:
评论

相关推荐

    DispatcherServlet 和 ContextLoaderListener 区别

    NULL 博文链接:https://angie.iteye.com/blog/2334955

    Spring的监听器ContextLoaderListener的作用

    Spring的监听器ContextLoaderListener的作用

    java解决org.springframework.web.context.ContextLoaderListener

    java解决org.springframework.web.context.ContextLoaderListener

    Web项目中使用Spring, 使用 Spring 的器监听器 ContextLoaderListener.docx

    一、Web项目中使用Spring ...在 Web 项目中使用 Spring 框架,首先要解决在 web 层(这里指 Servlet)中获取到 Spring容器的问题。只要在 web 层获取到了 Spring 容器,便可从容器中获取到 Service 对象

    spring和hibernate整合

    org.springframework.web.context.ContextLoaderListener <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener>

    web.xml中ContextLoaderListener的运行过程解析

    web.xml中ContextLoaderListener的运行

    Spring MVC 入门实例

    17 <listener-class>org.springframework.web.context.ContextLoaderListener 18 19 20 21 <filter-name>encodingFilter 22 <filter-class>org.springframework.web.filter.CharacterEncodingFilter 23 24 ...

    spring-web-2.5.jar

    org.springframework.web.context.ContextLoaderListener.class org.springframework.web.context.ContextLoaderServlet.class org.springframework.web.context.ServletConfigAware.class org.springframework.web....

    springweb3.0MVC注解(附实例)

    org.springframework.web.context.ContextLoaderListener </listener> <!-- Spring MVC 的Servlet,它将加载WEB-INF/annomvc-servlet.xml 的 配置文件, 以启动Spring MVC模块--> <servlet-name>annomvc ...

    Spring-5.1.5源码

    Spring framework 5.1.5源码 Main: spring-web/org.springframework.web.context.ContextLoaderListener

    spring源代码解析

    下面我们使用ContextLoaderListener作为载入器作一个详细的分析,这个Servlet的监听器是根上下文被载入的地方,也是整个 Spring web应用加载上下文的第一个地方;从加载过程我们可以看到,首先从Servlet事件中得到...

    整合struts2和spring源代码(可以直接在tomcat中运行)

    org.springframework.web.context.ContextLoaderListener 4.配置spring的配置文件(可以查看WEB-INF里面的applicationContext.xml文件) 注意:如果是默认,一定要放在WEB-INF中并文件名为...

    简单spring MVC 配置

    <listener-class>org.springframework.web.context.ContextLoaderListener <servlet-name>test <servlet-class>org.springframework.web.servlet.DispatcherServlet <load-on-startup>1 <servlet-name>...

    spring_MVC源码

    09. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 10. </listener> 11. 12. <servlet> 13. <servlet-name>spring</servlet-name> 14. <servlet-class>org.spring...

    Spring MVC 框架应用实例

    org.springframework.web.context.ContextLoaderListener <filter-name>encodingFilter org.springframework.web.filter.CharacterEncodingFilter <param-name>encoding ...

    struts2-spring-plugin-2.1.2.jar

    struts2与spring的整合。导入struts2-spring-... spring监听器对应的API类为:org.springframework.web.context.ContextLoaderListener。 struts2-spring-plugin包为我们将struts2的对象工厂设置为spring的IoC容器,

    springmybatis

    其实还有更简单的方法,而且是更好的方法,使用合理描述参数和SQL语句返回值的接口(比如IUserOperation.class),这样现在就可以至此那个更简单,更安全的代码,没有容易发生的字符串文字和转换的错误.下面是详细...

    ssh整合时遇到常见错误 ContextLoaderListener not found 解决

    ssh整合时 被虐的经验之谈。内容虽然比较少,也是前人的工作经验。

    SPRING API 2.0.CHM

    ContextLoaderListener ContextLoaderPlugIn ContextLoaderServlet ContextRefreshedEvent ContextSingletonBeanFactoryLocator ControlFlow ControlFlowFactory ControlFlowFactory.Jdk13ControlFlow ...

    spring-simple-web:使用 Spring Framework 的简单 Web (WAR) 项目

    Web 应用程序使用 Spring Web 侦听器初始化,例如web.xml org.springframework.web.context.ContextLoaderListener 。 Spring Web 侦听器使用web.xml的contextConfigLocation上下文参数进行初始化。 此设置的...

Global site tag (gtag.js) - Google Analytics