1.添加相关依赖。
<!--Spring Security和thymeleaf的整合依赖-->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity4</artifactId>
</dependency>
<!--thymeleaf模板引擎-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!--Security安全框架-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
需要注意的是,这里使用了thymeleaf模板引擎来进行前端页面数据交互,默认的thymeleaf版本太低,需要将它修改为更高版本,否则访问页面将会报错。在properties元素中修改版本。
<properties>
<java.version>1.8</java.version>
<!--