2012-03-22 34 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

相关问题