Thymeleaf 3.0 Spring Boot + Security integration does not work

前端 未结 3 729
执念已碎
执念已碎 2021-01-18 13:19

I struggle to get Thymeleaf to work with Spring Security in my Spring Boot 1.4.3 based project.

Tags like e.g.

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-18 14:02

    If you use Spring Boot 2.0.0.RELEASE:

    
        org.springframework.boot
        spring-boot-starter-parent
        2.0.0.RELEASE
         
    
    

    you need just the following dependencies:

    
        org.springframework.boot
        spring-boot-starter-security
    
    
        org.thymeleaf.extras
        thymeleaf-extras-springsecurity4
    
    

    Version of thymeleaf-extras-springsecurity4 will be inherited from the spring-boot-starter-parent and would be 3.0.2.RELEASE.

    Thanks to @yglodt for pointing this out.


    Also in your templates add spring-security namespace xmlns:sec="http://www.thymeleaf.org/extras/spring-security" and use hasRole instead of hasAuthority value in tag:

    ...

提交回复
热议问题