i'm working on simple project that implement spring security. the issue come when i tried to work with Logout link with Spring and Thymeleaf.
1.pom.xml
<!--Spring Boot Dependencies - Security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- Dependencies Spring Security-->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
<version>2.1.2.RELEASE</version>
<scope>compile</scope>
</dependency>
navbar.html
<ul class="nav navbar-nav navbar-right">
<!--<li><a th:href="@{/login}" th:text="#{navbar.login.text}"></a></li>-->
<li th:if="${#authorization.expression('isAuthenticated()')}">
<a th:href="@{/login}" th:text="#{navbar.login.text}"/>
</li>
<li th:if="${#authorization.expression('isAuthenticated()')}">
<form id="f" th:action="@{/logout}" method="post" role="form" class="navbar-form">
<button type="submit" th:text="#{navbar.logout.text}" class="btn btn-primary"/>
</form>
</li>
</ul>
This error happens when the Thymeleaf Extras Spring Security version is not compatible with the Spring Framework version, in its case, the Spring Boot version works with the Spring Framework version 5.x and the Thymeleaf Extras Spring Security version you have is 4.x. You need update the artifactId in your pom.xml and either choose a compatible version or let Spring Boot choose the version for you
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
<scope>compile</scope>
</dependency>
Collected from the Internet
Please contact javaer1[email protected] to delete if infringement.
Comments