1

applicationcontext.xml について 1 つ質問があります...

web.xml がサーバー (Tomcat など) によって解釈されるとき、最初に applicationcontext.xml または struts.xml を参照しますか?

(または) 最初に struts.xml があるかどうかを確認し、次に applicationcontext.xml を解釈してから struts.xml に戻り、applicationcontext.xml 環境を struts.xml に含めてから、struts.xml を解釈しますか?

流れが知りたいです。

私はstruts2とSpring 3フレームワークを使用しています...

皆さん、ありがとうございました..

4

1 に答える 1

1

次の web.xml を検討してください

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <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>  
    <welcome-file-list>
        <welcome-file>/index.action</welcome-file>
    </welcome-file-list>
</web-app>

フィルタは発生順に初期化されます。したがって、間違いなく struts.xml は applicationContext.xml の前に読み取られますが、逆の場合は逆になります。これはサーブレット仕様の一部であり、ここに明示的に記載されています: http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContextListener.html

ただし、サーブレットを使用してリソースにアクセスした場合は、フィルターの後に初期化され、順序はサーブレットの load-on-startup 要素によって制御できます。

于 2012-03-22T18:35:23.327 に答える