-
Notifications
You must be signed in to change notification settings - Fork 38.3k
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
PathMatchingResourcePatternResolver does not consider manifest based classpaths [SPR-13685] #18260
Comments
Kazuki Shimizu commented Running on Spring Boot 1.4, same resource is resolved form an executable jar file. I think it is related with this changes. e.g )
Java code is : package com.example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.stream.Stream;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Autowired
public void configureTestProperties(TestProperties properties) {
Stream.of(properties.getResources()).forEach(resource -> {
try {
System.out.println(resource.getURL());
} catch (IOException e) {
e.printStackTrace();
}
});
}
@Component
@ConfigurationProperties(prefix = "my.app.test")
public static class TestProperties {
private Resource[] resources;
public Resource[] getResources() {
return resources;
}
public void setResources(Resource[] resources) {
this.resources = resources;
}
}
}
Run as :
Result is :
Expect is (Spring Boot 1.3.8.RELEASE) :
|
Juergen Hoeller commented
|
Kazuki Shimizu commented Hi Juergen Hoeller and Stéphane Nicoll, Should I make a new Issue ? |
Stéphane Nicoll commented Nope, sorry the issue isn't assigned to me and I missed that notification from my todo list. |
Andy Wilkinson commented The fix for spring-projects/spring-boot#7003 may well be relevant here. It would be interesting to know if the behaviour differs between Spring Boot 1.4.1 and 1.4.2. |
Kazuki Shimizu commented I've added repro project on my GitHub account. Please see https://github.com/kazuki43zoo/repro-PathMatchingResourcePatternResolver. |
Stéphane Nicoll commented Andy Wilkinson there is a difference. 1.4.2 brings xml files located in nested JARs while 1.4.1 doesn't. But both versions exhibit the duplication. However something I didn't noticed initially is that the file is duplicated three times:
Notice in the second line there is |
Stéphane Nicoll commented Thanks Kazuki Shimizu, I've just created #19501 |
Kazuki Shimizu commented Hi Stéphane Nicoll, Thanks for your work!! I'll watch the #19501. |
Phil Webb opened SPR-13685 and commented
The
PathMatchingResourcePatternResolver
has aaddAllClassLoaderJarRoots
method which is used to find jar files on the classpath. The current implementation usesURLClassLoader.getURLs()
to find items.Unfortunately, it appears that
URLClassLoader.getURLs()
doesn't include elements that were added to the classpath inMETA-INF/MANIFEST.MF
but not passed tojava -cp
. As Maven uses this technique to launch tests, it's pretty easy to get into a situation where tests fail but production code works.This bug was originally raised in spring-projects/spring-boot#4438 and a repro project is included https://github.com/MichaelF25/spring-boot-messagesource-bug
Affects: 4.2.2
Issue Links:
PathMatchingResourcePatternResolver
provides duplicate resources when usingclasspath*:
prefix combined with ant-style [SPR-15989] #20539 PathMatchingResourcePatternResolver provides duplicate resources when using classpath* prefix combined with ant-stylePathMatchingResourcePatternResolver
returns duplicate resources when usingclasspath*:
prefix [SPR-16117] #20665 PathMatchingResourcePatternResolver returns duplicate resources when using classpath* prefixReferenced from: commits 08748ec
0 votes, 6 watchers
The text was updated successfully, but these errors were encountered: