`

web中使用beanRefContext.xml的方式加载spring

 
阅读更多

步骤1、
将beanRefContext.xml 放在classpath 目录下,并在其中的businessBeanFactory中加载其他配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
            <bean id="businessBeanFactory"
                    class="org.springframework.context.support.ClassPathXmlApplicationContext">
                    <constructor-arg>
                            <list>
                                    <value>applicationContext-datasource.xml</value>
                                    <value>applicationContext-dao.xml</value>
                                    <value>applicationContext-serviceImpl.xml</value>
                            </list>
                    </constructor-arg>
            </bean>
    </beans>
 

步骤2、web.xml中配置加载

<context-param>
        <param-name>locatorFactorySelector</param-name>
        <param-value>classpath:beanRefContext.xml</param-value>
</context-param>
<context-param>
        <param-name>parentContextKey</param-name>
        <param-value>businessBeanFactory</param-value>
</context-param>
<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

 

 

。。

分享到:
评论
2 楼 qq85609655 2014-07-03  
xigua366 写道
用了beanRefContext.xml的方式加载spring,为什么还要配置监听器启动spring呢?
beanRefContext.xml的方式加载spring的方式有什么好处,什么情况下要这样配置呢?

配置了启动监听器,才能加载xml文件,但是,如果spring的xml配置文件有多个,那么就用到businessBeanFactory,实际上,这个多个配置也可以放到监听器里面。
1 楼 xigua366 2014-06-18  
用了beanRefContext.xml的方式加载spring,为什么还要配置监听器启动spring呢?
beanRefContext.xml的方式加载spring的方式有什么好处,什么情况下要这样配置呢?

相关推荐

    项目配置文件( spring-mvc.xml spring-mybatis.xml web.xml log4j.properties)

    这里提到的四个关键配置文件——`spring-mvc.xml`、`spring-mybatis.xml`、`web.xml`以及`log4j.properties`,对于一个基于Java的Web应用来说至关重要,特别是使用Spring MVC和MyBatis框架的时候。接下来,我们将...

    加载spring 文件,在web.xml中的配置

    当我们谈论“加载Spring文件,在web.xml中的配置”时,主要是指如何在Web应用启动时初始化Spring IoC(Inversion of Control,控制反转)容器并加载配置文件。 1. **使用ContextLoaderListener** `&lt;listener&gt;`标签...

    web.xml加载顺序与web.xml常用节点解析

    - `&lt;servlet&gt;`和`&lt;servlet-mapping&gt;`:定义Servlet及其URL映射,与过滤器类似,Servlet的加载和处理请求的顺序也遵循`web.xml`中的顺序。 - `&lt;listener&gt;`:定义监听器类,可以监听Web应用程序的特定事件,如`...

    SpringMVC基于代码的配置方式(零配置,无web.xml)

    传统的SpringMVC配置往往依赖于XML文件,如web.xml和spring-servlet.xml等,但随着Spring框架的发展,出现了基于代码的配置方式,实现了零XML配置,提高了开发效率。本文将详细介绍如何在不使用web.xml的情况下,...

    web.xml文件中配置(servlet, spring, filter, listenr)的加载顺序

    ### web.xml文件中配置(servlet, spring, filter, listener)的加载顺序 在Java Web应用开发中,`web.xml`文件是整个Web应用程序的核心配置文件之一,它定义了Servlet容器如何启动、初始化以及配置各个组件如...

    spring在web.xml中和在struts中的不同配置..pdf

    在本文中,我们将探讨Spring在`web.xml`中的配置与在Struts中的配置差异,以及这两种配置方式背后的基本原理。 首先,Spring的核心是ApplicationContext,它是一个管理Bean的容器,可以看作是应用程序的上下文环境...

    Spring全注解project示例 (无web.xml配置)

    标题 "Spring全注解project示例 (无web.xml配置)" 提供了我们即将探讨的核心主题:一个使用Spring框架,完全依赖注解配置的项目,且没有传统的web.xml部署描述符。这种配置方式在现代Spring应用中非常常见,因为它...

    spring4的所有jar包+applicationContext.xml+web.xml

    此外,还可以配置Spring的ContextLoaderListener,该监听器会加载`applicationContext.xml`,使得Spring的IoC容器能够在Web应用启动时初始化。 4. **Spring4的新特性**: - **Java配置**:Spring4增强了对Java配置...

    web.xml+详细解析.rar

    在Java Web开发中,`web.xml`文件是核心配置文件,它是应用服务器启动时加载的部署描述符,用于定义Web应用程序的结构、配置及行为。本篇将深入探讨`web.xml`的重要概念、元素、属性以及在实际项目中的应用。 1. **...

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

    在Java Web开发中,`org.springframework.web.context.ContextLoaderListener` 是Spring框架的一部分,它负责初始化一个Web应用程序的Spring上下文。这个监听器是基于Servlet容器(如Tomcat、Jetty等)的,当Web应用...

    spring如何摒弃hibernate.cfg.xml

    在现代的Spring应用程序中,整合Hibernate时,我们通常会选择使用Spring的IoC(Inversion of Control)容器来管理数据访问层,而不是直接依赖于Hibernate的配置文件`hibernate.cfg.xml`。这是因为Spring提供了更高级...

    spring boot + mybatis +mapper.xml 项目

    5. **MyBatis-Spring整合**: 要在Spring Boot中使用MyBatis,需要集成MyBatis-Spring。这使得MyBatis与Spring的事务管理可以无缝结合,同时提供Bean的自动扫描和SqlSessionFactory/SqlSessionTemplate的自动注入。 ...

    web.xml配置servlet,filter,listener加载顺序源代码

    本源码将详细介绍web.xml配置中servlet,filter,listener的加载顺序,可以让学习者更好的了解web.xml各种属性配置,自己写的东西,不足之处请大家见谅,顺便收点积分也好下资料,谢谢

    javax.xml.ws.Service 报错需要的包

    在Java开发中,`javax.xml.ws.Service` 是一个核心组件,属于Java API for XML Web Services (JAX-WS)的一部分,用于创建客户端和服务端的Web服务代理。报错通常表明缺少必要的依赖包,这可能会影响到程序的正常运行...

    如何加载jar包中的spring配置文件

    然而,当配置文件位于jar包内部时,我们需要调整加载方式。 **步骤1:配置文件的组织** 在SSM整合中,Spring配置文件通常包括Spring MVC的配置(如`dispatcher-servlet.xml`)、Spring的根上下文配置(如`...

    Spring在web.xml中的配置详细介绍

    这通常在Servlet、Filter或Listener中实现,以便于在Web层中使用Spring管理的bean。 例如,在Servlet中获取Spring上下文: ```java WebApplicationContext appContext = WebApplicationContextUtils.get...

    spring.jar spring-webmvc-struts.jar spring-webmvc.jar

    标题中的"spring.jar"、"spring-webmvc-struts.jar"和"spring-webmvc.jar"都是Spring框架相关的Java库文件,通常以.jar结尾的文件是Java的归档文件,包含了类、资源和元数据,用于Java应用程序的运行。这些文件在...

    SpringBoot之logback-spring.xml不生效的解决方法

    在这个例子中,问题可能是由于类加载器的搜索路径不包括自定义的`logback-spring.xml`位置。 为了解决这个问题,我们可以采取以下几种策略: 1. **检查配置文件的位置**:确保`logback-spring.xml`位于`src/main/...

    springmvc、spring、mybatis的resources配置文件和web.xml

    在Java Web开发中,Spring MVC、Spring和MyBatis是三个非常重要的框架,它们共同构建了一个灵活、高效的应用架构。这些框架的配置文件对于整个应用的运行至关重要,下面将详细讲解它们各自的资源配置以及与`web.xml`...

    快速搭建一个java config(无web.xml)的web工程(一)

    在早期的Spring应用中,配置主要通过XML文件完成,但随着Spring的发展,Java Config的出现使得我们可以使用纯Java代码来配置应用,减少了XML的使用,提高了可读性和维护性。本篇文章将指导你如何快速搭建一个不依赖...

Global site tag (gtag.js) - Google Analytics