【问题标题】:Undefined attribute name (sec:authentication)未定义的属性名称(sec:authentication)
【发布时间】: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 thymeleaf


    【解决方案1】:

    我只是复制了 sec 标签的命名空间,html 警告消失了

    <html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:th="http://www.thymeleaf.org"
        xmlns:sec="http://www.thymeleaf.org">
    

    【讨论】:

      【解决方案2】:

      Joel 的回答效果很好但这是Official Guidelines 中建议的正确名称空间

      xmlns:sec="http://www.thymeleaf.org/extras/spring-security"

      【讨论】:

        【解决方案3】:

        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>
        

        【讨论】:

        猜你喜欢
        • 2012-09-16
        • 2023-02-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-01
        • 2019-01-31
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多