Replace template folder not found exceptions with warnings
One of the nice things about Spring Boot is that it typically works out of the box. When using the Thymeleaf starter this is not true (#424).
We should change Spring Boot to work without additional actions by the user.
One option is to provide a default template. It was mentioned that this could not be done https://github.com/spring-projects/spring-boot/issues/424#issuecomment-36639256. However, I think we could make this work by placing the default templates in a different location (i.e. org/springframework/boot/autoconfigure/thymeleaf/templates/). Then Spring Boot's Auto Configuration would wire the application to point to this default template location if the location was not found.
UPDATE I think the important thing here is to ensure this works out of the box. My suggestion on how to fix it is not necessarily the best way to ensure it works out of the box.
+1 for providing a default template explaining how to resolve the situation. Friendlier and more opinionated than failing the application IMO.
It seems this is a rather common issue, see StackOverflow.
Can you explain how that default template would be a catch-all? Also, start.spring.io creates the default templates package for you when it detects a template engine. Is the issue different if the templates package does not exist at all?
I think you only get the log in that case which is good. So maybe we should fix that in start.spring.io since it creates the directory?
Can you explain how that default template would be a catch-all?
I'm not sure I understand. I don't know that we would make it a catch-all. I think we would ensure that Spring Boot starts up regardless of if the folder exists (in some way).
It seems weird if the user hasn't even specified any request mappings that it fails on startup if the template location does not exist.
Also, start.spring.io creates the default location for you when it detects a template engine. Is the issue different if the template package does not exist at all?
No. In either case the IDE does not add the empty template folder to the classpath (https://github.com/spring-projects/spring-boot/issues/424#issuecomment-36722322).
I think you only get the log. So maybe we should fix that in start.spring.io since it creates the directory.
Furthermore, start.spring.io can't fix the user experience for all conditions. For example, if a user leverages start.spring.io and later adds the Thymeleaf starter then scaffolding does not help.
+1 for providing a default template or starting w/o failing. A log message might be sufficient to warn the user instead of failing.
+1 for default template, or a log message that allow startup
+1 Could be possible to add another pre-requisite: validate if there are any template in order to enable thymeleaf auto-configuration?
+1
Most of the Template auto-configurations have some form of the same check so we can't just fix this for Thymeleaf.
+1 for default template and no errors out-of-the-box.
+1 for checkTemplateLocation=false in thymeleaf autoconfig. I just add "spring.thymeleaf.checkTemplateLocation=false" to the generated application.properties to get started. No reason it cant be false by default imo.
I think the easiest solution is to change checkTemplateLocationExists() to log a warning rather than throw an exception. Adding a default template is going to be a lot more work and impact more than just Thymeleaf.
@philwebb +1 for the warning and no default template.
I think the easiest solution is to change checkTemplateLocationExists() to log a warning rather than throw an exception. Adding a default template is going to be a lot more work and impact more than just Thymeleaf.
@philwebb This sounds good to me. The main goal is to make it so the application starts up without additional work (i.e. needing to create a template).
@philwebb & @rwinch, would it be better to log an error vs. a warning?
I would personally prefer a warning if the application starts regardless.
@jregehr I think it makes more sense to log a warning as @philwebb suggests. The reason is that we don't know that the application is not going to work. For example, if the user is never sent to a Thymeleaf template. This might happen if there is another view resolver, the user is writing to the response directly (i.e. REST app), etc.
+1
I'd say "a clear warning on the console, plus not blowing up". No particular preference for a "replace this page" placeholder template or just not having anything at all, but this is annoying in the early stages of a project that will have Thymeleaf but only has scaffold @RestControllers.
+1 it makes more sense to log a warning