2016-12-22 4 views
1

Der Gehalt an web.xmlWie wurde ApplicationContext geladen?

<servlet> 
    <servlet-name>spring</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>spring</servlet-name> 
    <url-pattern>/krams/*</url-pattern> 
</servlet-mapping> 

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

Es gibt auch eine applicationContext.xml Datei in WEB.INF aber es ist in web.xml nicht vorhanden. Wie wurde es geladen?

+0

... wahrscheinlich von org.springframework.web.context.ContextLoaderListener? Es ist sehr unklar, was Sie wirklich hier fragen, warum kümmert es dich? – Gimby

+0

Mögliches Duplikat von [Wo befindet sich die genaue Position der Spring-Konfigurationsdatei und web.xml?] (Http://stackoverflow.com/questions/17444410/where-is-the-exact-location-of-spring-config-file) -und-web-xml) –

Antwort

0

ContextLoaderListerner, ContextLoader und XmlWebApplicationContext Klassen sind verantwortlich für das Laden von applicationContext.xml.

Bitte werfen Sie einen Blick auf ihren Quellcode auf Git.

Sie werden feststellen, dass ContextLoaderListerner erweitert ContexLoader ist.

In der ContextLoader Dokumentation haben sie erwähnt, dass:

* If not explicitly specified, the context implementation is supposed to use a 
* default location (with XmlWebApplicationContext: "/WEB-INF/applicationContext.xml"). 

Und dieser Wert in XmlWebApplicationContext erwähnt wird wie folgt (mit anderen konstanten Werten, wenn Sie sie benötigen):

/** Default config location for the root context */ 
public static final String DEFAULT_CONFIG_LOCATION = "/WEB-INF/applicationContext.xml"; 

/** Default prefix for building a config location for a namespace */ 
public static final String DEFAULT_CONFIG_LOCATION_PREFIX = "/WEB-INF/"; 

/** Default suffix for building a config location for a namespace */ 
public static final String DEFAULT_CONFIG_LOCATION_SUFFIX = ".xml"; 

Und das ist ein Grund, warum die Datei "applicationContext.xml" geladen wird, obwohl sie nicht in der Datei "web.xml" konfiguriert ist. Sie werden einige Zeit brauchen, um all diese von Spring verwendeten Standardkonfigurationen (Magie) zu verstehen.

Verwandte Themen