2016-10-03 17 views
0

私はwebappを再構成しています。ディスパッチャーサーブレットからすべてをContextLoaderListenerに移動したいspring mvc; contextConfigLocationロードオーダー

質問1、私は複数のアプリケーション・コンテキストxmlファイルを持っている場合は、それがどのような順序それらがロードされない(これは、この質問の範囲を超えて、セキュリティ構成の変更によるものですか)?たとえば、context:component-scanを含むxmlファイルは、xmlファイルがDAOとサービスBeanを指定する前にロードする必要がありますか?

質問2、(または、この議論の余地がある?)どのように私はC_applicationContext.xml前にロードすべきA_applicationContext.xmlがB_applicationContext.xml前にロードする必要があると仮定してロードされている_applicationContext.xmlを*順序を指定します

次のように私のweb.xmlは次のとおりです。

<web-app id="WebApp_ID" version="2.4" 
 
     xmlns="http://java.sun.com/xml/ns/j2ee" 
 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
 
     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 
 

 
     <servlet> 
 
      <servlet-name>AssessmentDelivery</servlet-name> 
 
      <servlet-class> 
 
      org.springframework.web.servlet.DispatcherServlet 
 
      </servlet-class> 
 
      <load-on-startup>1</load-on-startup> 
 
     </servlet> 
 
     
 
     <servlet-mapping> 
 
     <servlet-name>AssessmentDelivery</servlet-name> 
 
     <url-pattern>/</url-pattern> 
 
    </servlet-mapping> 
 

 

 
    <context-param> 
 
     <param-name>contextConfigLocation</param-name> 
 
     <param-value>/WEB-INF/config/*_applicationContext.xml</param-value> 
 
    </context-param> 
 

 
    <!-- security filter --> 
 
    <filter> 
 
    \t \t <filter-name>springSecurityFilterChain</filter-name> 
 
    \t \t <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
 
    \t </filter> 
 

 
    \t <filter-mapping> 
 
    \t \t <filter-name>springSecurityFilterChain</filter-name> 
 
    \t \t <url-pattern>/*</url-pattern> 
 
    \t </filter-mapping> 
 

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

答えて

3

ヒント:

最近では、SpringからJavaconfigの設定を検討しています。

が質問1に答えるためにと2を使用すると、以下の理解が非常に重要です:あなたが実行すると

  • アプリの春は春で作成および管理すべてのBeanが存在するApplication Contextを作成します。今でApplication Contextのために、それは2つの「サブ」アプリケーションコンテキストから作成すべきであると考え、通常、それらはServletApplicationContextRootApplicationContext
    • 前者は、そのようなあなたの@Controller sと、Webに関するすべてをスキャンする方法をマニュアルに「言及」していますsおよび@Bean「は、このような@Service@Repositories@BeanなどViewResolverなどのためなどのインフラについての...
    • 以降は、すべてのサーバーについてスキャンする必要があり、」は、DataSource用などのインフラについてなど

は、次のことを理解して非常に重要です:

  • ServletApplicationContext - >RootApplicationContext
    • それは、前者が後者にアクセスを得ることができることを意味し(使用依存性について、それはすなわち:@Controller@Serviceを必要とします) 。したがって、Web側がserver側にアクセスできることが反映されています。

したら、これは次のようにない可能

  • RootApplicationContextであることを特徴とする - >ServletApplicationContext
    • サーバー側からの豆は、Web側にアクセスしたいということは意味がありません(悪い習慣)

長い時間前、私はweb.xml使用しませんが(<init-param>経由)

  • DispatcherServlet + contextConfigLocationServletApplicationContext
  • ContextLoaderListener + contextConfigLocation<context-param>経由)RootApplicationContext

表しそれ豆が宣言されているかどうかは関係ありません:

  • XML
  • JavaConfig
  • 注釈@Controllerなど

春の豆が作成されているものために、約サイクルを管理します。だから、.xmlファイル(あなたの場合)がどのように宣言されているか(注文について)は関係ありません。

関連する問題