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