Attempted to call method expression(java.lang.String) on null context object
<p>I am using security in my spring app.</p>

<pre><code>&lt;dependency&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
&lt;/dependency&gt;
</code></pre>

<p>and here is my controller for login:</p>

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

<p>then I have made menu and there I tried to make logout button:</p>

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

<p>I can <strong>login correctly</strong>, but when it loads the menu it complains with:</p>

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

<p>How can I fix it?</p>