我在applicationcontext.xml上有一个问题......
当服务器(tomcat或其他)解释web.xml时..它首先看到applicationcontext.xml或struts.xml
(或)首先看看是否存在struts.xml,然后解释applicationcontext.xml,然后返回struts.xml并将applicationcontext.xml环境包含到struts.xml中,然后解释struts.xml
我想知道流程是怎么回事。
我正在使用struts2和spring 3框架......
谢谢大家..
答案 0 :(得分: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>
按发生顺序初始化过滤器。因此大多数情况下,绝对在applicationContext.xml之前读取struts.xml,但是如果相反则反之亦然。它是servlet规范的一部分,在此处明确说明:http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContextListener.html
但是,如果您使用servlet访问资源,则会在过滤器之后对其进行初始化,并且可以通过servlet load-on-startup元素控制顺序。