javaspring-mvcclasspathapplicationcontext

Output classpath content from within Spring context configuration


Does Spring provide any way to output the actual content of the classpath environment variable when it is loading a resource in a context configuration file?

<!-- Import the special context --> 
<import resource="classpath:mySpecialApplicationContext.xml"/> 

I set the Log4J logging level to ALL for Springframework classes but this value does not appear to be logged by the framework. I am trying to figure out if Spring is loading this from a dependency, and I want to see the classpath setting during application runtime. The application is built by Maven with many dependencies.

If there are two or more mySpecialApplicationContext.xml's in the classpath, which one does Spring use?

Thank you.


Solution

  • You can see the relevant (I think) source code at https://fisheye.springsource.org/browse/spring-framework/org.springframework.core/src/main/java/org/springframework/core/io/DefaultResourceLoader.java?r=647495edd366bac67727a5be8e651fcca030e0aa

    In short:

    1. No, the classpath is not logged

    2. The details of what would be loaded when there is more than one matching resource in the classpath are ClassLoader dependent - the DefaultResourceLoader uses the thread's classloader, but typically, the first one found would be used.