Skip to content

Revisit hint on using classpath* for retrieving templates #23068

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

Closed
snicoll opened this issue Aug 24, 2020 · 4 comments
Closed

Revisit hint on using classpath* for retrieving templates #23068

snicoll opened this issue Aug 24, 2020 · 4 comments
Assignees
Labels
type: documentation A documentation update
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented Aug 24, 2020

See #23051 (comment)

@snicoll snicoll added the type: documentation A documentation update label Aug 24, 2020
@snicoll snicoll added this to the 2.2.x milestone Aug 24, 2020
@snicoll
Copy link
Member Author

snicoll commented Sep 7, 2020

I can see that TemplateLocation has an explicit branch for classpath* but I don't understand why.

@snicoll snicoll added the for: team-attention An issue we'd like other members of the team to review label Sep 7, 2020
@philwebb
Copy link
Member

philwebb commented Sep 8, 2020

It was added as fix for #2184

@snicoll
Copy link
Member Author

snicoll commented Sep 8, 2020

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.

@philwebb philwebb removed the for: team-attention An issue we'd like other members of the team to review label Sep 16, 2020
@snicoll
Copy link
Member Author

snicoll commented Sep 22, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

2 participants