3

私はthymeleaf-spring3 2.0.18Spring 3.1.1を使用しています。正常に動作するログイン ページを作成しましたが、他の Thymeleaf 属性は解析されますが、「sec:authorize」は解析されません。これは、生成されたビューのソース コードを確認すると確認できるためです。

依存関係や特定の構成など、不足しているものはありますか?

これは私の login.html です:

<!DOCTYPE html>
<head>
...
</head> 

<body>
<div class="top">
    <div class="container">         
        <ul class="loginbar pull-right">
            <li sec:authorize="isAnonymous()"><a href="/login" class="login-btn">Login</a></li>   
            <li sec:authorize="isAuthenticated()" class="login-btn">Welcome <span sec:authentication="name">Bob</span></li>   
        </ul>
    </div>      
</div><!--/top-->

<!--=== Content Part ===-->
<div class="container">     
    <div class="row-fluid">
        <form name="f" th:action="@{/j_spring_security_check}" method="post" class="log-page">
            <h3>Login</h3>
            <div th:if="${loginError}" th:with="errorMsg=${session['SPRING_SECURITY_LAST_EXCEPTION'].message}" class="alert alert-error">
                Bad user or password.<br/>
                Cause: <span th:text="${errorMsg}">Wrong input!</span>
            </div>    
            <div class="input-prepend">
                <span class="add-on"><i class="icon-user"></i></span>
                <input name="j_username" class="input-xlarge" type="text" placeholder="Username" />
            </div>
            <div class="input-prepend">
                <span class="add-on"><i class="icon-lock"></i></span>
                <input name="j_password" class="input-xlarge" type="password" placeholder="Password" />
            </div>
            <div class="controls form-inline">
                <button class="btn-u pull-right" type="submit">Login</button>
            </div>
        </form>
    </div><!--/row-fluid-->
</div><!--/container-->     
<!--=== End Content Part ===-->

</body>
</html> 
4

2 に答える 2

11

この例を見ると、pom.xml に依存関係を追加する必要があることがわかりました。

<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-springsecurity3</artifactId>
    <version>2.0.1</version>
    <scope>compile</scope>
</dependency>

templateEngineまた、 Beanに方言を追加する必要もあります。

<bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
    <property name="templateResolver" ref="templateResolver"/>
    <property name="additionalDialects">
        <set>
            <bean class="org.thymeleaf.extras.springsecurity3.dialect.SpringSecurityDialect"/>
        </set>
    </property>
</bean>
于 2013-09-29T13:19:45.020 に答える
0

同様の問題があり、メイン コントローラー コンテキスト構成にパッケージ スキャンを追加することで解決しました。

<context:component-scan base-package="org.thymeleaf.extras.springsecurity3" />
于 2013-10-04T20:41:10.200 に答える