I use Spring Boot v2.7.0, installed from "start.spring.io" and from there I installed Thymeleaf, and as I searched in the parent-pom I found out that: thymeleaf-spring5 (v3.0.15.RELEASE), thymeleaf-extras-java8time (v3.0.4.RELEASE)
Lately, I needed to apply the pattern <form th:method="put/delete".../>. After googling in verious places, I found the solution, which was reffered in the book as well: "Taming Thymeleaf Practical Guide to building a web application with Spring Boot and Thymeleaf - Wim Deblauwe" which is the top/excellent books of Thymeleaf, and from which I learn Thymeleaf. Acoording to these, I did:
Step 1:
Added this property in application.properties:
spring.mvc.hiddenmethod.filter.enabled=true
and I tried it in the application.yaml (as a 2nd solution, because the previous did not work), like this way:
spring:
mvc:
hiddenmethod:
filter:
enabled: true
Step 2:
I used:
<form th:method="put".../>
<form th:method="delete".../>
Step 3:
Finally I used the: "@PutMapping, @DeleteMapping" in my controller handler methods.
The result was the error message:
There was an unexpected error (type=Method Not Allowed, status=405).
Request method 'POST' not supported
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.handleNoMatch(RequestMappingInfoHandlerMapping.java:253)
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:442)
After googling I found this solution, to add the needed bean by myself with the following way, which DID WORKED:
@Bean
public FilterRegistrationBean<HiddenHttpMethodFilter> hiddenHttpMethodFilter() {
FilterRegistrationBean<HiddenHttpMethodFilter> filterRegistrationBean = new FilterRegistrationBean<>(new HiddenHttpMethodFilter());
filterRegistrationBean.setUrlPatterns(Arrays.asList("/*"));
return filterRegistrationBean;
}
I wonder why this configuration "spring.mvc.hiddenmethod.filter.enabled=true", does not add the needed bean in my case, and I have to add it by myself.
Anyone can help me on this, please? Thanks a lot in advance