`

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应用程序的特定事件,如`...

    详解Spring mvc的web.xml配置说明

    下面我们将详细探讨`web.xml`中涉及Spring MVC的主要配置项。 1. **监听器(Listener)** `web.xml`中的监听器允许我们在特定事件发生时执行代码,例如应用程序启动或关闭。在Spring MVC中,`org.springframework....

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

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

    struts.xml和applicationContext.xml、web.xml的配置

    在Java Web开发中,`struts.xml`, `applicationContext.xml` 和 `web.xml` 是三个至关重要的配置文件,它们各自负责不同的职责,并协同工作来构建一个完整的应用框架。以下是关于这三个配置文件的详细说明。 首先,...

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

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

    在Web应用中web.xml利用Spring配置log4j

    在Web应用中web.xml利用Spring配置log4j

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

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

    spring无web.xml零配置

    在现代的Spring框架开发中,"spring无web.xml零配置"是一种常见的实践,它通过Java配置(javaconfig)替代了传统的XML配置方式。这种方式使得应用更加灵活,代码更易于理解和维护。下面我们将深入探讨这个主题。 ...

    springMVC零配置,无web.xml,无spring配置

    在现代的Java Web开发中,Spring MVC框架以其灵活性和强大的功能深受开发者喜爱。然而,传统的Spring MVC项目往往依赖于XML配置文件,如`web.xml`和`spring-servlet.xml`等,来定义和管理应用程序的组件。随着Java...

    spring如何摒弃hibernate.cfg.xml

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

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

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

    提取apk文件中的AndroidManifest.XML

    对于每个APK,它使用Apktool的`d`命令进行反编译,将输出保存到与APK同名的新目录中,并将AndroidManifest.xml复制到输出目录,文件名改为`AndroidManifest_原始文件名.xml`。最后,删除临时的反编译目录,以保持...

    spring boot + mybatis +mapper.xml 项目

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

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

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

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

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

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

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

    SSH三大框架整合 struts2(使用xml配置)+hibernate(使用xml配置)+spring(使用xml配置)

    SSH是Java Web开发中的三个重要框架,分别是Struts2、Hibernate和Spring,它们共同构建了一个强大的MVC(Model-View-Controller)架构。本项目整合了这三个框架,并使用XML配置来管理各个组件,实现了基本的CRUD...

    struts.xml文件详解.doc

    在web.xml中,你可以使用"init-param"标签,而在struts.xml中,你可以使用"constant"标签来设置这些属性。这样做提供了更大的灵活性,让开发者能够根据需要动态调整框架的行为。 以下是一些struts.properties文件中...

Global site tag (gtag.js) - Google Analytics