I'm using springboot + thymeleaf and have just started setting up the project. At first this worked fine, showing my home page and account page, but I must've changed something somewhere because now it will only show home.
weird stuff 1: It takes the template home from the resources/templates folder, although I've configured it to not do that. My guess is it doesn't use the configuration.
weird stuff 2: It only finds the home template, not the account template.
What do I need to change to get this working again?
Configuration class:
@SpringBootApplication
@RestController
@Configuration
@ComponentScan("applikaasie.domein")
public class startApp {
public static void main(String[] args) {
SpringApplication.run(startApp.class, args);
}
@Bean
public ViewResolver viewResolver(SpringTemplateEngine templateEngine) {
ThymeleafViewResolver viewResolver = new ThymeleafViewResolver();
viewResolver.setTemplateEngine(templateEngine);
return viewResolver;
}
@Bean
public TemplateEngine templateEngine(TemplateResolver templateResolver) {
SpringTemplateEngine templateEngine = new SpringTemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
return templateEngine;
}
@Bean
public TemplateResolver templateResolver() {
TemplateResolver templateResolver = new ServletContextTemplateResolver();
templateResolver.setPrefix("/WEB-INF/templates");
templateResolver.setSuffix(".html");
templateResolver.setTemplateMode("HTML5");
System.out.println("templateResolver");
return templateResolver;
}
}
Account class:
@Controller
@RequestMapping(value="account")
public class AccountController {
@RequestMapping(value="/", method=GET)
public String greeting() {
return "home";
}
@RequestMapping(value="/accounts", method=RequestMethod.GET)
public String accountList(Model model) {
model.addAttribute(accountRepository.getAllAccounts());
return "accounts";
}
}
Directory structure:
/resources
/templates
account.html
home.html
/webapp
/WEB-INF
/templates
account.html
home.html
UPDATE
Resetting the computer fixed this. I guess something in memory was wrong.