2

I want to use thymeleaf templates in my spring boot application. I've some html pages in the src/resources/public directory and I want them to be served wihout writing a controller because I want to write a front end application. I can access the index.html file at http://localhost:8080/index.html but it's not using the thymeleaf syntax. How can I do it?

I've added the thymeleaf dependency, tried writing a SpringResourceTemplateResolver bean but still no luck. Here is what I've done so far:

@SpringBootApplication
public class MyApplication {

    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }

    @Bean
    public SpringResourceTemplateResolver templateResolver(){
        SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
        templateResolver.setPrefix("classpath:/public/");
        templateResolver.setSuffix(".html");
        templateResolver.setTemplateMode(TemplateMode.HTML);
        templateResolver.setCacheable(true);
        return templateResolver;
    }
}
Nayan
  • 1,362
  • 2
  • 12
  • 25
  • So you want to pre-generate the html and then place it on a directory which is accessible by a webserver? – gil.fernandes Aug 16 '18 at 09:30
  • Yes, something like that. I've a `base.html` and some `child.html`. I want to use thymeleaf to do this and VueJS to do api calls. I don't need spring controllers. – Nayan Aug 16 '18 at 09:49
  • See this: https://stackoverflow.com/questions/64775008/spring-boot-cant-resolve-thymeleaf-templates/64780037#64780037 – gtiwari333 Nov 11 '20 at 03:27

0 Answers0