-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Thymeleaf templates preceded by a slash are found when running in an IDE but not when running from a jar #1744
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
It seems to be a basic limitation of the JDK. This small class:
Run in an IDE:
Run with
|
We could possibly do something in LanchedURLClassLoader to turn more than one consecutive slash into a single slash but I'm not sure it's worth it. |
Seems like this might be a common mistake, it's been raised again in #2057. Striping double slashes might be an option but we need to check that this won't break existing code. |
Following on from #2507...with more (poss. important?) details. I originally didn't have preceding '/' characters on my view names. The problem came when I introduced spring security: @Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable();
http
.authorizeRequests()
.antMatchers("/").permitAll()
.anyRequest().authenticated();
http
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/home")
.failureUrl("/login?error")
.permitAll()
.and()
.logout()
.invalidateHttpSession(true)
.logoutSuccessUrl("/login?logout")
.permitAll();
} I found that I could not use simply 'login' instead of '/login', etc. (maybe SS is dong something different to Thymeleaf?) So I needed to find a solution that preserved the slash at the beginning of view names, while stripping the duplicate away. Thus I adopted the classpath configuration:
|
Having review the behavior of the standard Given the following code:
Running the application from an IDE will print return This shows that our fat jar support is working in the same way as the standard JDK and I think it's best to keep consistency rather than introduce a difference and potentially break things in other ways. |
If it's a common mistake, I think giving a warning message would be helpful. |
For more information see spring-projects/spring-boot#1744
Just as an extra information. I have a similar issue and there it works in the IDE and Tomcat. So I think the default jdk is inconsistent, would be great to get a warning. |
Yo tenia el mismo problema, la solución la encontré en este link. https://stackoverflow.com/questions/27249078/spring-boot-gives-templateinputexception-error-resolving-template-when-runnin Okay, I found where you have to take a close look. In your Controller classes, when you use An Example Snippet @Controller
@RequestMapping("property")
public class PropertyController {
@NonNull PropertyService service;
@GetMapping("/list")
public String list() {
return "property/list";
}
} |
Is this issue resolved? I have the following code:
It works starting with Spring Boot using Maven: If I change the code above to return the template without the slash in the beginning, it works on both:
Is it the expected behaviour or this issue should've fixed that? |
When you return the URI starting with a slash, you always send a double slash. The difference is that starting with Spring the file system deals with this issue, which doesn't do the JVM, when you run the .jar. |
I'm using Spring Boot 2.0.0.RELEASE and I'm experiencing this, I've tried removing slashes on my RequestMapping but I'm still getting HTTP 500. Is there a solution for this? |
Have you checked the links in the .html (Thymeleaf template)? There you could be generating double slashes as well. |
@oratengG4S we don't use the tracker for questions. Please ask on StackOverflow or join us on Gitter. |
See http://stackoverflow.com/questions/26493831/spring-boot-thymeleaf-not-resolving-fragments-after-packaging. I'm not sure that there's anything we can do but I'd like to investigate.
The text was updated successfully, but these errors were encountered: