今天使用thymeleaf,因为使用了thymeleaf3的语法,发现thymeleaf一直报错,刚开始非常奇怪,命名语法是没有问题的,然后,看了一下项目依赖包中的thymeleaf版本,发现SpringBoot(使用的是1.5.10版本)默认集成的是thymeleaf2,于是增加了版本设置
<thymeleaf.version>3.0.9.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.2.0</thymeleaf-layout-dialect.version>
然后,继续重新运行程序,发现还是报错,这次是thymeleaf-security报错,org.springframework.expression.spel.SpelEvaluationException Property or field 'name' cannot be found on null;
大概就是, ${#authentication.name} 报错了,感觉很苦恼,找了很久才发现,thymeleaf-security4的版本,应该和 thymeleaf 版本一致,SpringBoot 1.5.10 默认的thymeleaf-security4版本,也是2,修改pom文件,增加版本属性后,果然可以正常运行了;
总结:
1、使用插件的版本需要注意,相同类型或相关联的应保持一直,
2、基础知识不够扎实,不懂原理,报错完全不知道什么原因