ThymeLeaf в Spring Boot Невозможно найти местоположение шаблона: путь к классам:/templates/JAVA

Программисты JAVA общаются здесь
Ответить
Anonymous
 ThymeLeaf в Spring Boot Невозможно найти местоположение шаблона: путь к классам:/templates/

Сообщение Anonymous »


I want to config some simple controller `@Configuration public class Config implements WebMvcConfigurer {

@Autowired private final ApplicationContext applicationContext; public Config(ApplicationContext applicationContext) { this.applicationContext = applicationContext; } @Bean public SpringResourceTemplateResolver templateResolver(){ SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver(); templateResolver.setApplicationContext(applicationContext); templateResolver.setPrefix("/WEB-INF/views/"); templateResolver.setSuffix(".html"); return templateResolver; } @Bean public SpringTemplateEngine templateEngine(){ SpringTemplateEngine templateEngine = new SpringTemplateEngine(); templateEngine.setTemplateResolver(templateResolver()); templateEngine.setEnableSpringELCompiler(true); return templateEngine; } @Override public void configureViewResolvers(ViewResolverRegistry registry) { ThymeleafViewResolver resolver = new ThymeleafViewResolver(); resolver.setTemplateEngine(templateEngine()); registry.viewResolver(resolver); }` `@Controller @RequestMapping("/people") public class ControllerPeople {

private final PersonDAO personDAO; @Autowired public ControllerPeople(PersonDAO personDAO) { this.personDAO = personDAO; } @GetMapping("/test") public String test(){ return "people/test"; } @GetMapping() public String index(Model model){ model.addAttribute("people", personDAO.index()); return "people/index"; } @GetMapping("/{id}") public String show(@PathVariable("id") int id, Model model){ model.addAttribute("person", personDAO.getPeople()); return "people/show"; } }`

When the application start I'm receiving this message.

2024-03-03T15:40:59.935+03:00 WARN 9616 --- [ main] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates, check your Thymeleaf configuration, or set spring.thymeleaf.check-template-location=false) And when I'm tring to move to localhost URL I'm receiving this exception

org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "ServletContext resource [/WEB-INF/views/people/index.html]") at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:235) ~[thymeleaf-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100) ~[thymeleaf-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:649) ~[thymeleaf-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1103) ~[thymeleaf-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1077) ~[thymeleaf-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.thymeleaf.spring6.view.ThymeleafView.renderFragment(ThymeleafView.java:372) ~[thymeleaf-spring6-3.1.2.RELEASE.jar:3.1.2.RELEASE] at org.thymeleaf.spring6.view.ThymeleafView.render(ThymeleafView.java:192) ~[thymeleaf-spring6-3.1.2.RELEASE.jar:3.1.2.RELEASE]

If I understand it correctly in this rows in config I'm showing when find out my view or problem isn't here templateResolver.setPrefix("/WEB-INF/views/"); templateResolver.setSuffix(".html");

And my view just in case

Sorry for my English I was try to say it in person

I was try to create another testing views and move views to resources/templates


Источник: https://stackoverflow.com/questions/780 ... -templates
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «JAVA»