-
Notifications
You must be signed in to change notification settings - Fork 38.5k
PathMatchingResourcePatternResolver duplicates module/file resources #29934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I see several ways to fix this, I think the one having less risk of consequences is cleaning the set before returning it in the If I've time (maybe next weekend) I'll write a pull request for you to decide but it looks like an easy fix. |
We have some measures in place for the automatic detection of duplicates already, in particular through conversion to So thanks for the report, I'll sort this out today. Maybe you could test a 6.0.5 snapshot before the release next week then, double-checking that it works in your scenario. |
that's what I planned to think about in my push request :)
Unfortunately I already switched to an annotation definition for all our persistence definition, since we have an internal delivery soon and I couldn't wait (I'm working for a client so I can't really share the code for testing)
and this in a class annoted @configuration
and the class was annoted in a DataJpaTest class |
The creation of an Maybe it should be solved as follows, buy not directly calling protected Resource convertClassLoaderURL(URL url) {
return (ResourceUtils.URL_PROTOCOL_FILE.equals(url.getProtocol()) ?
new FileSystemResource(ResourceUtils.getFile(url)) : new UrlResource(url));
} Similar problems:
|
Affects: <6.0.4>
When upgrading from spring-core-5.3.24.jar to spring-core-6.0.4.jar (spring-boot 2 to 3 upgrade)
Our test uses
persistence.xml
descriptions for persistence units. The test fails for a duplicated persistence unit.main cause found in debugger:
the set created at org.springframework.core.io.support.PathMatchingResourcePatternResolver#getResources line 325 with one element returned by
findAllModulePathResources(locationPatternWithoutPrefix)
:org.springframework.core.io.FileSystemResource
whose Path (its hash source material) is/C:/SomePath/target/test-classes/META-INF/persistence.xml
then the set is completed line 332 by the result of
findAllClassPathResources(locationPatternWithoutPrefix)
, which returns the same resource as the old version (spring-core-5.3.24):org.springframework.core.io.UrlResource
whose getCleanedUrl() (its hash source material) isfile:/C:/SomePath/target/test-classes/META-INF/persistence.xml
(notice thefile:
prefix)The found resources are the same file resource in 2 different Java structures, but their hash being solved differently, they both are added to the set, and therefore this resource conflicts with itself.
Consequence:
the method org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager#preparePersistenceUnitInfos fails the test at line 470 because the persistence units are duplicated (but they come from the same source).
The text was updated successfully, but these errors were encountered: