2016-05-24 14 views
1

私は春のアプリケーションでセキュリティを使用しています。nullコンテキストオブジェクトのメソッド式(java.lang.String)を呼び出そうとしました

<dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-starter-security</artifactId> 
     </dependency> 

、ここでのログインのための私のコントローラである:

@Configuration 
    static class ClientWebConfig extends WebMvcConfigurerAdapter { 
    public void addViewControllers(ViewControllerRegistry registry) { 
     registry.addViewController("/login").setViewName("fragments/login"); 
    } 
    } 

それから私は、menueをしたし、そこに私は、ログアウトボタンを作ってみました:

<li th:if="${#authorization.expression('isAuthenticated()')}"> 
     <a href="/logout" th:href="@{/logout}">Logout</a> 
    </li> 

私はlogin correctlyことができますが、ときに文句を言うメニューを読み込みます。

org.springframework.expression.spel.SpelEvaluationException: EL1011E:(pos 15): Method call: Attempted to call method expression(java.lang.String) on null context object 

どうすれば修正できますか?

+0

あなたの依存関係リストで春のセキュリティのためのthymeleaf拡張を持っていますか? –

答えて

3

権限オブジェクトの最後に疑問符を追加して、使用前にヌルかどうかを確認してください。

$ {#認証?.expression( 'にisAuthenticated()')}

+0

それは私のために働く。ありがとう –

関連する問題

 関連する問題