When I use classpath : **/mapper/*. xml configuration searches for files and finds no corresponding files, but when configured to classpath : com/**/mapper/*. xml can find the corresponding file.

What is the logical difference between these two configurations that results in different results. The corresponding file is placed in the dependent jar. spring boot version 2.7.2

Comment From: bclozel

Please provide a sample application reproducing the problem, something that we can git clone and run.

Thanks!

Comment From: firekirin67

Thank you for your reply

Project Address: https://github.com/firekirin67/classpath_test.git

The project uses the mybatis-plus ORM framework, an extended version of mybaits. Configured in application. yml mybatis-plus: mapper-location: classpath:/mapper/.xml

Here the Resourcepatternresolver is used internally to search for matches

jdk version:1.8.301

When the HTTP request (localhost: 8081/test) is called to the corresponding ORM framework for processing it should be a normal return of 1, but an exception is thrown when the corresponding XML file is not found. By modifying the mapper-location: classpath * : configuration attribute value in application.yml, you will get different return information

Comment From: firekirin67

When I read Pathmatchingresourcepatternresolver, the property configuration values described earlier are indeed implementation-differentiated.

PathMatchingResourcePatternResolver uses the classloader of the current class. The getResources method implementation.

When configuring:"**/mapper/*.xml", the PathMatchingResourcePatternResolver is passed to the classloader. The getResources method is an empty string, gets the Classpath directory, and the PathMatchingResourcePatternResolver retrieves the path of the current class object to its package and the jar package corresponding to the ExtClassLoader. The only thing you get from getresources is that the Classpath Directory doesn't get the file path of the dependencies under the Classpath package.

When using"com/**/mapper/*.xml" to match the search, the JVM's own implementation retrieves the dependency files in the Classpath and gets the corresponding dependency files. The pathmatching Resourcepatternresolver then performed a second file retrieval match

Comment From: bclozel

I think this works as designed from a Spring perspective. Depending on the resource prefix being used, a different resolver will be used and resource resolution will be different. See https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#resources-resourcepatternresolver

If you disagree somehow with the behavior or the documentation you should reach out to the mybatis-plus-boot-starter maintainers as I don't think that Spring Boot is in charge of this configuration property.

Thanks!

Comment From: firekirin67

Thank you for your reply