Почему не работает Thymeleaf аутентификация в Spring Security? При этом другие теги thymeleaf работают...
@Configuration
public class WebSecurityConfig implements WebMvcConfigurer {
........
@Bean
public SpringResourceTemplateResolver setupViewResolver() {
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver ();
resolver.setSuffix(".html");
resolver.setCharacterEncoding("UTF-8");
return resolver;
}
@Bean
public SpringTemplateEngine templateEngine() {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(setupViewResolver());
templateEngine.setEnableSpringELCompiler(true);
return templateEngine;
}
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
ThymeleafViewResolver resolver = new ThymeleafViewResolver();
resolver.setTemplateEngine(templateEngine());
resolver.setCharacterEncoding("UTF-8");
registry.viewResolver(resolver);
}
}
WebApplicationInitializer
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
root.scan("com.example");
servletContext.addListener(new ContextLoaderListener(root));
ServletRegistration.Dynamic appServlet = servletContext.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext()));
appServlet.setLoadOnStartup(1);
appServlet.addMapping("/");
servletContext.addFilter("securityFilter", new DelegatingFilterProxy("springSecurityFilterChain"));
}
В
pom.xml
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
</dependency>
Не работает именно аутентификация:
<div sec:authorize="isAuthenticated()">
Оно выводится как обычная html разметка. Как это исправить?