See https://github.com/spring-projects/spring-boot/issues/23051#issuecomment-679191023
Comment From: snicoll
I can see that TemplateLocation
has an explicit branch for classpath*
but I don't understand why.
Comment From: philwebb
It was added as fix for #2184
Comment From: snicoll
I don't understand the problem reported in #2184. I've tried to reproduce it and was unable to do so. I've created an empty package in a library and then used this library as a dependency of sample with the following code:
@Bean
public ApplicationRunner applicationRunner(ApplicationContext context) {
return (args) -> System.out.println("Templates --> " + context.getResource("classpath:/templates").getURI());
}
I've ran this sample with the IDE (exploded classpath), mvn spring-boot:run
and java -jar
. All of them gave me the expected output (the templates
location in the library).
Given that the fix for #2184 does not have additional test, I am now questioning that anyExists
makes a difference. According to my discussion with @jhoeller it shouldn't as you need to have a pattern in the path for it to make any sense considering we're not looking for resources with the same name.
The current note states:
Depending on how you run your application, IntelliJ IDEA orders the classpath differently. Running your application in the IDE from its main method results in a different ordering than when you run your application by using Maven or Gradle or from its packaged jar. This can cause Spring Boot to fail to find the templates on the classpath.
I don't understand how ordering has any effect since ultimately we need to make sure a templates
directory on the whole classpath exists.
Comment From: snicoll
We've decided to remove the documentation note in 2.2.x
forward and remove the code only in 2.4.x
in case there is a side effect we haven't foreseen.