【发布时间】:2017-06-01 01:12:37
【问题描述】:
我是第一次使用 Spring Boot 创建网站。我正在使用一个测试页面来显示,一旦用户登录,当用户登录时,“Authenticated”字样就会出现在屏幕上。
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
</head>
<body>
<h2>Thymleaf example</h2>
<p sec:authorize="hasRole('ROLE_USER')">
Authenticated
</p>
</body>
</html>
但是,问题是带有 sec:authorize 的标签仍然未经编辑和解析。因此,无论用户是否登录,都会出现 Authenticated 字样。从控制器打印用户的权限可以确认这一点。
我的 pom.xml 文件具有以下依赖项。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
... dependencies for mysql and jdbc are omitted.
感谢任何帮助。 注意,我使用的是 Spring Boot,所以 JAVA 配置优先于 XML 配置。
【问题讨论】:
标签: spring spring-mvc spring-boot thymeleaf