This KB describes how to obtain the list of resources read by Spring Framework ApplicationContext by using Spring Framework APIs.
Spring Framework 6.0
This can be implemented with below code, parameter of context.getResources() can be changed from "classpath*:**/*" to something else like "classpath*:**/*.xml" if you only want to obtain particular resources.
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.io.Resource;
public class DemoApplication {
public static void main(String[] args) throws Exception {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(DemoApplication.class);
// Example: list all XML files Spring can see
Resource[] resources = context.getResources("classpath*:**/*");
System.out.println("=== Resources visible to ApplicationContext ===");
for (Resource resource : resources) {
System.out.println(resource.getURL());
}
context.close();
}
}