Thymeleaf - Why can't I access templates on a spring-mvc application?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Thymeleaf - Why can't I access templates on a spring-mvc application?

gtludwig
I'm re-engineering an application and am moving slightly away from the automagically preconfigured spring-boot into a more spring-mvc based approach.

The project structure is shown in the picture:






















All my Thymeleaf configuration is defined in a separate class:

@Configuration
public class ThymeleafConfiguration {

    @Bean
    public ServletContextTemplateResolver templateResolver() {
        ServletContextTemplateResolver resolver = new ServletContextTemplateResolver();
        resolver.setPrefix("templates/");
        resolver.setSuffix(".html");
        resolver.setTemplateMode("HTML5");
        resolver.setOrder(1);
        return resolver;
    }

    @Bean
    public SpringTemplateEngine templateEngine() {
        SpringTemplateEngine engine = new SpringTemplateEngine();
        engine.setTemplateResolver(templateResolver());
        return engine;
    }

    @Bean
    public ThymeleafViewResolver thymeleafViewResolver() {
        ThymeleafViewResolver resolver = new ThymeleafViewResolver();
        resolver.setTemplateEngine(templateEngine());
        return resolver;
    }
}

My SecurityConfiguration class is defined as:

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    // other methods and beans

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers(
                        "/images/**",
                        "/css/**",
                        "/js/**",
                        "/health/**",
                        "/api/**",
                        "/reports/**",
                        "/h2-console/**",
                        "/oauth/authorize",
                        "/oauth/confirm_access",
                        "/oauth/token_key").permitAll()
                .antMatchers("/admin/**").hasAuthority(RoleEnum.BASE_ADMIN.toString())
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
                .logout()
                .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
                .logoutSuccessUrl("/login")
                .and()
                .headers()
                .frameOptions()
                .sameOrigin()
                .and()
                .csrf()
                .disable();
    }
}

Still, I get this error:

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "login", template might not exist or might not be accessible by any of the configured Template Resolvers

I'm kind of lost here. What am I not seeing and how do I get this to work?

I have also posted this same message on stackoverflow, here:

https://stackoverflow.com/questions/46320269/thymeleaf-why-cant-i-access-templates-on-a-spring-mvc-application