How do I add Thymeleaf SpringSecurityDialect to spring boot

前端 未结 2 810
礼貌的吻别
礼貌的吻别 2021-01-13 01:03

In the configuration of my template engine I would like to add SpringSecurityDialect() like:

@Bean
public TemplateEngine templateEngine() {
    SpringTemplat         


        
相关标签:
2条回答
  • 2021-01-13 01:40

    As @Lachezar already answered, you have to add those missing dependencies. But the specified version with ext['thymeleaf.version'] = '3.0.0.RELEASE should be the same as in the compile dependencies so you better use ext['thymeleaf.version'] = '3.0.1.RELEASE'.

    Furthermore, please not that it is enough to just specify a bean for the security dialect without providing a bean for the template engine. With Thymeleaf on the classpath, it will automatically recognize that the bean is an instance of IDialect and adds it directly to the dialects:

    @Bean
    public SpringSecurityDialect springSecurityDialect() {
        return new SpringSecurityDialect();
    }
    
    0 讨论(0)
  • 2021-01-13 01:49

    It means that org.thymeleaf.extras:thymeleaf-extras-springsecurity4 has a dependency to org.thymeleaf:thymeleaf as you can see in the link to the repo above. Apparently you haven't provided this dependency. The class IExpressionEnhancingDialect is there. You can resolve that by adding the dependency to your project.

    Since this may get a bit complicated... I'm also playing around with Spring Boot, spring security and the security dialect for thymeleaf (plus spring data with h2). Here are my gradle dependencies for reference, they may help you somehow:

    ext['thymeleaf.version'] = '3.0.1.RELEASE'
    ext['thymeleaf-layout-dialect.version'] = '2.0.0'
    
    dependencies {
        compile("org.springframework.boot:spring-boot-devtools")
        compile("org.springframework.boot:spring-boot-starter-web")
        compile("org.springframework.boot:spring-boot-starter-thymeleaf")
        compile("org.springframework.boot:spring-boot-starter-data-jpa")
        compile("org.springframework.boot:spring-boot-starter-security")
        compile("org.thymeleaf.extras:thymeleaf-extras-springsecurity4:3.0.1.RELEASE")
    
        compile("com.h2database:h2")
    }
    

    Note that I want to use thymeleaf 3 instead of 2, that is why there are some extra unpleasant tweaks in my configuration.

    EDIT: The version of thymeleaf-extras-springsecurity4 should be the same as thymeleaf.version as suggested in the other answer.

    0 讨论(0)
提交回复
热议问题