2012-03-22 65 views
1

我有一個applicationContext.xml的問題...的applicationContext.xml如何解釋在Struts和Spring

在web.xml中由服務器解釋(Tomcat或其他)..它首先看到的applicationContext.xml或struts.xml

(或者)首先查看是否存在struts.xml,然後解釋applicationcontext.xml,然後返回到struts.xml並將applicationcontext.xml環境包含到struts.xml中,然後解釋struts.xml

我想知道流程如何。

我使用Struts2的春季3框架...

謝謝大家..

+0

struts.xml與S2相關,由FilterDispatcher處理,而application-context依賴者如何指定contextloader listern在哪裏搜索它。兩者都是不同的,並以自己的方式工作。 – 2012-03-22 16:04:44

回答

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之前讀取的,但如果顛倒過來,情況就會如此。它是servlet規範的一部分,並在此明確指出:http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContextListener.html

如果您使用servlet訪問資源,那麼在過濾器和順序可以由servlet控制之後,它將被初始化load-on-startup元素。

+1

我認爲首先會執行applicationcontext.xml。鏈接... http://docs.oracle.com/cd/B15904_01/web.1012/b14017/filters.htm#i1000023所以在請求發生之前,第一個聽衆將採取放置然後過濾器來... – user533 2012-03-23 04:03:32

+0

我的意思是說每個監聽器都是按照web.xml中出現的順序實例化的,我想這意味着他們的配置文件也會按照這個順序進行解析。 – Quaternion 2012-03-23 19:01:31

相關問題