【发布时间】: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