Finding Resources with PathMatchingResourcePatternResolver and URLClassloader in JARs

前端 未结 2 523
眼角桃花
眼角桃花 2020-12-08 07:05

I am trying to load all resources with a specific file-extension which are loaded dynamically at runtime using a URLClassloader.

Unfortunately the PathMatchingResour

2条回答
  •  一整个雨季
    2020-12-08 07:38

    Loading the files dynamically in Spring is simple, I'd change the approach to finding the files with extensions.

    Try the following:

    ClassLoader cl = this.getClass().getClassLoader(); 
    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(cl);
    Resource[] resources = resolver.getResources("classpath*:/*.xml") ;
    for (Resource resource: resources){
        logger.info(resource.getFilename());
    }
    

提交回复
热议问题