我第一次使用Spring Boot创建网站。 我正在使用测试页面来展示,一旦用户登录,屏幕上将显示“已验证”的字样。
<!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配置。
Exception in thread "main" java.lang.NoClassDefFoundError: org/thymeleaf/dialect/IExpressionEnhancingDialect
以及Caused by: java.lang.ClassNotFoundException: org.thymeleaf.dialect.IExpressionEnhancingDialect
- needoriginalname<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
- Robert Humethymeleaf-extras-springsecurity4
依赖项中:<version>3.0.1.RELEASE</version>
(目前最新版本)。 - Robert Humethymeleaf-extras-springsecurity4
的2.1.3.RELEASE
版本。 - WildDev