【问题标题】:Updated dependencies and Thymeleaf tags don't work更新的依赖项和 Thymeleaf 标签不起作用
【发布时间】:2019-05-25 21:57:44
【问题描述】:

将我的依赖项和项目更新为最新版本的 Spring Boot 2.1.1,突然安全标签不起作用。我正在使用 Thymeleaf。

pom.xml

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.1.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
        <version>2.1.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-springsecurity4</artifactId>
        <version>3.0.4.RELEASE</version>
    </dependency>
    ...
</dependencies>

我的 HTML:

<!DOCTYPE html>
  <html xmlns="http://www.w3.org/1999/xhtml"xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.w3.org/1999/xhtml">
  <head>
   <title></title>
  </head>
  <body>
    <div sec:authorize="isAuthenticated()"> <!-- Doesn't work -->
      ...
    </div>
  </body>
  </html>

【问题讨论】:

  • 并不是因为 Spring Boot 2.1 使用了不同的依赖项
  • 您在链接的答案中尝试了xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4"? (或者在这种情况下是springsecurity5)
  • 两者都不是。我用xmlns:sec="http://www.w3.org/1999/xhtml"。所以,唯一需要改变的是依赖关系。
  • 好的,很高兴成功了!

标签: maven spring-boot spring-security thymeleaf


【解决方案1】:

https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.1-Release-Notes#thymeleaf-spring-security-extras

Thymeleaf 的 Spring Security Extras 模块的依赖管理和自动配置已从 thymeleaf-extras-springsecurity4 切换到 thymeleaf-extras-springsecurity5。如果您正在使用该模块,您应该更新您的 pom.xml 或 build.gradle 以依赖 thymeleaf-extras-springsecurity5。

所以更新后的 pom.xml 应该改变以下依赖:

<dependency>
     <groupId>org.thymeleaf.extras</groupId>
     <artifactId>thymeleaf-extras-springsecurity4</artifactId>
     <version>3.0.4.RELEASE</version>
</dependency>`

到:

<dependency>
     <groupId>org.thymeleaf.extras</groupId>
     <artifactId>thymeleaf-extras-springsecurity5</artifactId>
     <version>3.0.4.RELEASE</version>
</dependency>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-20
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多