Pramit Sinha
Pramit Sinha

Reputation: 33

Location of files in classpath section of web.xml inside WAR (spring application)

I am new to spring. While going through an application I found that its web.xml contains the following -

<context-param>
    <param-value>
        classpath:com/abc/def/ghijkl.xml            
    </param-value>
</context-param>

I am trying to understand that when you build a WAR of this application, does the ghijkl.xml file get compiled too? I have been digging into the WAR and havent found any refernce to the xml files there. Can someone please guide me through this?

Upvotes: 1

Views: 1434

Answers (1)

erhun
erhun

Reputation: 3649

Context parameters which can be read from all servlets in your application, in Spring project this is used as below.

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:context.xml</param-value>
    </context-param>

You declare all servlets can access too these beans which are defined in context.xml.

I am trying to understand that when you build a WAR of this application, does the ghijkl.xml file get compiled too?

xml files are not compiled, they are used in runtime when the application is start(deploy to application server and initial start)

I have been digging into the WAR and havent found any refernce to the xml files there

It should some reference if it is not you get an runtime exception when you start your application like below stacktrace

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [com/abc/def/ghijkl.xml]; nested exception is java.io.FileNotFoundException: class path resource [com/abc/def/ghijkl.xml] cannot be opened because it does not exist
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
    at  org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: class path resource [sasa.xml] cannot be opened because it does not exist
    at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)
    ... 21 more

Upvotes: 1

Related Questions