Spring boot - how to determine template locations correctly?

After some time to work with the Spring app (and Spring boot, for that matter) it seems like I'm finally going to get it working.

I already went through dependency resolution and already created maven. The application starts (and very fast!), But when I try to access

localhost:8080

I get the following browser message when I try to get to the application’s landing page:

HTTP Status 500 - Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "home/homeNotSignedIn", template might not exist or might not be accessible by any of the configured Template Resolvers

Folder src/main/resources-

src/main/resources
    static // CSS, IMG and JS
    templates // html
    application.properties
    log4j.properties

Now I understand that I can mix concepts, but on mine ApplicationConfiguration.javaI have this:

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "b.c.g.c")
public class ApplicationConfiguration extends WebMvcConfigurerAdapter {

    @Bean
    @Description("Thymeleaf template resolver serving HTML 5")
    public ServletContextTemplateResolver templateResolver() {
        ServletContextTemplateResolver templateResolver = new ServletContextTemplateResolver();
        templateResolver.setCacheable(false);
        templateResolver.setTemplateMode("HTML5");
        templateResolver.setCharacterEncoding("UTF-8");
        templateResolver.setPrefix("classpath:/templates/");
        templateResolver.setSuffix(".html");

        return templateResolver;
    }

    @Bean
    @Description("Thymeleaf template engine with Spring integration")
    public SpringTemplateEngine templateEngine() {
        SpringTemplateEngine templateEngine = new SpringTemplateEngine();
        templateEngine.addDialect(new SpringSecurityDialect());
        templateEngine.addDialect(new LayoutDialect(new GroupingStrategy()));
        templateEngine.setTemplateResolver(templateResolver());

        return templateEngine;
    }

    @Bean
    @Description("Thymeleaf view resolver")
    public ViewResolver viewResolver() {

        ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
        viewResolver.setTemplateEngine(templateEngine());
        viewResolver.setCharacterEncoding("UTF-8");
        viewResolver.setCache(false);
        viewResolver.setOrder(1);

        return viewResolver;
    }

    // other beans
}

And, on application.properties, I have this:

spring.thymeleaf.check-template-location=true
spring.thymeleaf.prefix=classpath:templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false

Although I see that these excerpts say the same thing, I'm sure you can go, right?

So there are actually two questions:

1) how to make sure Spring + Timeleaf understands where to find the templates?

2) localhost:8080/appName localhost:8080/?

+4
1


.

  • application.properties application.yml( Yaml) src/main/resources. Spring -Boot , ( -), .

     server.context-path=/<appname>
    
  • Spring -boot, thymeleaf .

+2

Source: https://habr.com/ru/post/1653237/


All Articles