I am using security in my spring app.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
and here is my controller for login:
@Configuration
static class ClientWebConfig extends WebMvcConfigurerAdapter {
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("fragments/login");
}
}
then I have made menu and there I tried to make logout button:
<li th:if="${#authorization.expression('isAuthenticated()')}">
<a href="/logout" th:href="@{/logout}">Logout</a>
</li>
I can login correctly, but when it loads the menu it complains with:
org.springframework.expression.spel.SpelEvaluationException: EL1011E:(pos 15): Method call: Attempted to call method expression(java.lang.String) on null context object
How can I fix it?
Try by adding a question mark at the end of authorization object to check if it is null before using it.
${#authorization?.expression('isAuthenticated()')}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With