Skip to content

PathMatchingResourcePatternResolver can not work in spring boot 1.4.0.RELEASE when package a executable jar #7003

@peace0phmind

Description

@peace0phmind

Hi,

I'm using spring boot 1.3.0.RELEASE and using PathMatchingResourcePatternResolver to find mybatis mapper files with under code:

PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
sessionFactoryBean.setMapperLocations(resolver.getResources("classpath*:mybatis*/**/*Mapper.xml"));

It works fine under 1.3.0.RELEASE. For some reason I upgrade spring boot to 1.4.0.RELEASE, then it can not work.

I debug into the source ,find the code in PathMatchingResourcePatternResolver:

protected Set<Resource> doFindAllClassPathResources(String path) throws IOException {
        Set<Resource> result = new LinkedHashSet<Resource>(16);
        ClassLoader cl = getClassLoader();
        Enumeration<URL> resourceUrls = (cl != null ? cl.getResources(path) : ClassLoader.getSystemResources(path));
        while (resourceUrls.hasMoreElements()) {
            URL url = resourceUrls.nextElement();
            result.add(convertClassLoaderURL(url));
        }
        if ("".equals(path)) {
            // The above result is likely to be incomplete, i.e. only containing file system references.
            // We need to have pointers to each of the jar files on the classpath as well...
            addAllClassLoaderJarRoots(cl, result);
        }
        return result;
    }

The different between 1.4.0 and 1.3.0, the 'resourceUrls.hasMoreElements()' returned false and true.It seems that 'cl.getResources(path)' returned different object.

So, why this happened and how to resolve it?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions