Search code examples
spring-bootthymeleaf

Facing issue with Thymleaf integration with Spring boot version 3


Please refer to source code from github repo https://github.com/vishalmestri/SpringSecurity/tree/master/spring-security-ldap-with-db-authorization-master-mysql

I am trying to create POC where authentication will be done from LDAP and authroization will be done from mysql db.

Application is starting , authenticating , authorizing. But when it tries to render thymleaf view, it is throwing exception.

org.thymeleaf.exceptions.TemplateOutputException: An error happened during template rendering

I have put exception log in repository. https://github.com/vishalmestri/SpringSecurity/blob/master/spring-security-ldap-with-db-authorization-master-mysql/exception%20faced.txt

Code tried is given above in github repo. I am using spring boot 3.0.4 version.


Solution

  • Spring Boot 3 comes with Thymeleaf 3.1 which no longer supports #httpServerRequest, see https://www.thymeleaf.org/doc/articles/thymeleaf31whatsnew.html

    The recommended way to do this is to create a dedicated model attribute for what you need. Add this to your controller:

    @ModelAttribute("remoteUser")
    public Object remoteUser(final HttpServletRequest request) {
        return request.getRemoteUser();
    }
    

    Then you can use ${remoteUser} in your template.