Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
spring mvc;contextConfigLocation加载顺序_Spring_Spring Mvc - Fatal编程技术网

spring mvc;contextConfigLocation加载顺序

spring mvc;contextConfigLocation加载顺序,spring,spring-mvc,Spring,Spring Mvc,我正在重新配置一个webapp。我想将所有内容从DispatcherServlet移到ContextLoaderListener中。(这是由于安全配置的更改超出了此问题的范围) 问题1,如果我有多个应用程序上下文xml文件,它们的加载顺序是否重要?例如,在指定DAO和服务bean的xml文件之前,是否需要加载包含context:component scan的xml文件 问题2,(或者这是没有意义的?)假设A\U applicationContext.xml应该在B\U applicationCo

我正在重新配置一个webapp。我想将所有内容从DispatcherServlet移到ContextLoaderListener中。(这是由于安全配置的更改超出了此问题的范围)

问题1,如果我有多个应用程序上下文xml文件,它们的加载顺序是否重要?例如,在指定DAO和服务bean的xml文件之前,是否需要加载包含context:component scan的xml文件

问题2,(或者这是没有意义的?)假设A\U applicationContext.xml应该在B\U applicationContext.xml之前加载,而B\U applicationContext.xml应该在C\U applicationContext.xml之前加载,我将如何指定加载*\U applicationContext.xml的顺序

我的web.xml如下所示:


评估交付
org.springframework.web.servlet.DispatcherServlet
1.
评估交付
/
上下文配置位置
/WEB-INF/config/*\u applicationContext.xml
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
org.springframework.web.context.ContextLoaderListener
一些建议:

现在考虑通过JavaCon Fig.< /P>进行Spring的配置。 回答问题1和2非常重要,您必须了解以下内容:

  • 运行应用程序时,Spring会创建一个
    应用程序上下文
    ,其中存在Spring创建和管理的所有bean。现在,考虑到代码<应用程序上下文< /代码>,应该从两个“子”应用程序上下文创建,通常它们在文档中是如何被提及的:<代码> ServelAppultEngult和<代码> RootApplicationContext < /代码>
    • 前者应该扫描所有关于Web的信息,例如您的
      @Controller
      @Bean
      关于基础设施的信息,例如
      viewsolver
    • 后者应该扫描所有关于服务器的信息,例如
      @Service
      @Repositories
      以及
      @Bean
      关于基础设施的信息,例如
      数据源
了解以下内容非常重要:

  • ServletApplicationContext
    -->
    RootApplicationContext
    • 这意味着前者可以访问后者(它是关于使用依赖关系的,即:一个
      @控制器
      需要一个
      @服务
      )。因此,它反映了
      Web
      端可以访问
      服务器
一旦说了这一点,以下是不可能的

  • RootApplicationContext
    -->
    ServletApplicationContext
    • 没有感觉到来自服务器端的Bean想要访问web端(一种糟糕的做法)
很久以前我不使用
web.xml
但是

  • DispatcherServlet
    +
    contextConfigLocation
    (通过
    )表示
    ServletApplicationContext
  • ContextLoaderListener
    +
    contextConfigLocation
    (通过
    )表示
    RootApplicationContext
是否通过以下方式声明bean并不重要:

  • XML
  • JavaConfig
  • 注释
    @Controller
Spring管理关于bean创建顺序的循环。因此,无论
.xml
文件(在您的情况下)是如何声明的(关于顺序)