Делал небольшое приложение на spring boot с шаблонизатором mustache, приложение запускается нормально, но при входе в localhost:8080/ вылезает ошибка
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.UnsupportedOperationException: Template loading not configured] with root cause
java.lang.UnsupportedOperationException: Template loading not configured
2023-11-21 21:18:51.899 ERROR 44173 --- [nio-8080-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.UnsupportedOperationException: Template loading not configured] with root cause
java.lang.UnsupportedOperationException: Template loading not configured
at com.samskivert.mustache.Mustache$1.getTemplate(Mustache.java:1034) ~[jmustache-1.15.jar:na]
at com.samskivert.mustache.Mustache$Compiler.loadTemplate(Mustache.java:220) ~[jmustache-1.15.jar:na]
at com.samskivert.mustache.Mustache$IncludedTemplateSegment.getTemplate(Mustache.java:845) ~[jmustache-1.15.jar:na]
at com.samskivert.mustache.Mustache$IncludedTemplateSegment.execute(Mustache.java:831) ~[jmustache-1.15.jar:na]
at com.samskivert.mustache.Template.executeSegs(Template.java:170) ~[jmustache-1.15.jar:na]
at com.samskivert.mustache.Template.execute(Template.java:137) ~[jmustache-1.15.jar:na]
at org.springframework.boot.web.servlet.view.MustacheView.renderMergedTemplateModel(MustacheView.java:80) ~[spring-boot-2.5.2.jar:2.5.2]
at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:179) ~[spring-webmvc-5.3.8.jar:5.3.8]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:316) ~[spring-webmvc-5.3.8.jar:5.3.8]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1396) ~[spring-webmvc-5.3.8.jar:5.3.8]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1141) ~[spring-webmvc-5.3.8.jar:5.3.8]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1080) ~[spring-webmvc-5.3.8.jar:5.3.8]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) ~[spring-webmvc-5.3.8.jar:5.3.8]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.8.jar:5.3.8]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.3.8.jar:5.3.8]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:655) ~[tomcat-embed-core-9.0.48.jar:4.0.FR]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.8.jar:5.3.8]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764) ~[tomcat-embed-core-9.0.48.jar:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:228) ~[tomcat-embed-core-9.0.48.jar:9.0.48]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:163) ~[tomcat-embed-core-9.0.48.jar:9.0.48]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.48.jar:9.0.48]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:190) ~[tomcat-embed-core-9.0.48.jar:9.0.48]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:163) ~[tomcat-embed-core-9.0.48.jar:9.0.48]
at org.springframework.security.oauth2.client.filter.OAuth2ClientContextFilter.doFilter(OAuth2ClientContextFilter.java:60) ~[
и тд
Вот классы:
@Configuration
public class MvcConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
}
@Bean
public MustacheViewResolver mustacheViewResolver() {
MustacheViewResolver resolver = new MustacheViewResolver();
resolver.setPrefix("classpath:/templates/");
resolver.setSuffix(".mustache");
resolver.setCache(false);
return resolver;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**")
.addResourceLocations("/resources/");
}
}
@Controller
public class IndexController {
@GetMapping("/")
public String index(Principal principal)
{
if(principal != null)
{
return "redirect:/blog";
}
return "index";
}
}
@Controller
public class RegistrationController {
private final ProfileServiceImpl profileServiceImpl;
public RegistrationController(ProfileServiceImpl profileServiceImpl) {
this.profileServiceImpl = profileServiceImpl;
}
@GetMapping("/registration")
public String showRegistrationForm() {
return "registration";
}
@PostMapping("/registration")
public ResponseEntity<Response> handleRegistration(@RequestBody ProfileDTO profileDTO) {
Response response = profileServiceImpl.createProfile(profileDTO);
return ResponseEntity.ok(response);
}
}
@Controller
public class BlogController {
@GetMapping("/blog")
public String notes()
{
return "blog";
}
}
spring.datasource.url=jdbc:postgresql://localhost/****
spring.datasource.username=***
spring.datasource.password=**************
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
server.port=8080
spring.mustache.prefix=classpath:/templates/
spring.mustache.suffix=.mustache
spring.mustache.expose-request-attributes=true
<!DOCTYPE html>
<html xmlns:=http://www.w3.org/1999/xhtml>
<head>
{{> meta}}
<title>Регистрация</title>
</head>
<body>
<section class="container">
<div class="mx-auto border my-5 py-3 px-3 form">
<form action="/registration" method="post">
<div class="form-group">
<label for="password">Email</label>
<input class="form-control" id="email" type="text" name="email">
</div>
<div class="form-group">
<label for="email">Password</label>
<input class="form-control" id="password" type="text" name="password">
</div>
<div class="form-group">
<label for="name">Nickname</label>
<input class="form-control" id="username" type="password" name="username">
</div>
<input type="hidden" name="_csrf" value="{{_csrf.token}}"/>
<input class="button" type="submit" value="Регистрация"/>
</form>
</div>
</section>
</body>
</html>