【发布时间】:2016-05-18 01:29:21
【问题描述】:
我在 Spring Security 简单 POC 中使用 Thymleaf。下面是我在 home.html 文件中的示例代码。
Hello <span sec:authentication="name">User</span>!i
如何摆脱 html 警告
Undefined attribute name (sec:authentication).
【问题讨论】:
我在 Spring Security 简单 POC 中使用 Thymleaf。下面是我在 home.html 文件中的示例代码。
Hello <span sec:authentication="name">User</span>!i
如何摆脱 html 警告
Undefined attribute name (sec:authentication).
【问题讨论】:
我只是复制了 sec 标签的命名空间,html 警告消失了
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org">
【讨论】:
Joel 的回答效果很好但这是Official Guidelines 中建议的正确名称空间
xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
【讨论】:
1) 将此依赖添加到pom.xml:
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity3</artifactId>
<version>3.0.0.BETA01</version>
</dependency>
2) 为templateEngine bean 添加额外的方言:
<!-- Thymeleaf Template Engine (Spring4-specific version) -->
<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolvers">
<set>
<ref bean="templateResolver" />
</set>
</property>
<property name="additionalDialects">
<set>
<bean class="org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect" />
</set>
</property>
</bean>
【讨论】: