考虑下面的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