Spring reading multiple Application Context with the same name from classpath

39 views Asked by At

I have a Spring MVC application which has an application context named as "applicationContext.xml", apart from having the beans defined, it uses the "import" tag to read another application context which comes from classpath (specifically, the application context file is placed inside a jar). The XML statements are as follows,

<!-- applicationContext.xml -->
<import resource="classpath:applicationContext.xml"/>

Notice that there are two application context named as the same (applicationContext.xml)

The issue I am facing is that when I run in the application in IntelliJ the application throws error while starting.

Whereas, in a deployed environment, the error occurs intermittently.

The error log is as follows, Error Log

I understand it says the XML is invalid, however I have verified it thoroughly and it is valid.

However, I have resolved this error by renaming the applicationContext.xml which comes from the classpath and changing the "import" resource,

Versions Used:-

  1. Tomcat:9.0.78
  2. Spring: 5.3.29
  3. Java: Coretto JDK 8.0372
  4. InteliJ:Ultimate 2023.2

I would really like to understand why and what can be the actual cause. Aren't the same names allowed ?,is it trying to read to the same applicationContext.xml , instead from the jar ?

0

There are 0 answers