springboot+springsecurity+thymeleaf的使用方式十分简单,用一个类继承WebSecurityConfigurerAdapter并重写方法即可和@EnableWebSecurity开启服务,交给spring管理
遇到的两个问题错误
sec:authentication,sec:authorize 失效问题
An error happened during template parsing (template: “class path resource [templates/index.html]”)模板解析错误
第一:版本问题
springboot和springsecurity版本不匹配,会产生thymeleaf和security联合使用不生效问题
thymeleaf和springsecurity以及thymeleaf-extras-springsecurity的版本配合问题,如果是springboot2.1.0以上则可用thymeleaf-extras-springsecurity5,因为thymeleaf和springsecurity都是5.如果想用thymeleaf-extras-springsecurity4,则需降到需要将springboot的版本调低至2.0.9及以下。
第二:模板解析错误
则是在HTML页面设置有误,导致模板解析不了
开头需注意引用问题,在thymeleaf中使用springsecurity
html lang=“en” xmlns:th=“http://www.thymeleaf.org”
xmlns:sec=“http://www.thymeleaf.org/thymeleaf-extras-springsecurity5”
sec:authorize :判断信息是否存在
sec:authentication:取出相应的值