在classpath中打印spring.xml的路径 [英] Printing path of spring.xml in classpath

查看:70
本文介绍了在classpath中打印spring.xml的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的测试类中使用以下代码,在classpath和application-content.xml文件中加载所有spring.xml文件。

I am using the below code in my test class , to load all the spring.xml files in classpath and application-content.xml file.

@Override
protected String[] getConfigLocations() {
    return new String[] {
        "classpath*:META-INF/spring.xml", "application-context.xml"};
}

有没有办法打印所有spring.xml文件的路径在classpath?我有许多jar文件,其中包含spring.xml。但是,运行测试可能不需要其中一些。有没有办法打印它们(jar文件或路径),还删除了不需要编程的spring.xml文件?

Is there a way to print path of all the "spring.xml" files in classpath? I have a number of jar files which have spring.xml in them. However some of these might not be required for running the tests. Is there a way to print them (jar files or path) and also remove the spring.xml files that are not required programattically?

推荐答案

试试这个:

ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver(new DefaultResourceLoader());
Resource[] resources = patternResolver.getResources("classpath*:META-INF/spring.xml");

for(Resource resource : resources) {
   System.out.println(resource.getDescription());
}

这有点不足,并使用非公开的Spring API,但它应该用于有限的诊断目的。

It's a bit underhand, and uses the non-public Spring API, but it should work for limited diagnostic purposes.

这篇关于在classpath中打印spring.xml的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆