I am trying to do Integration Test (JUNIT) on a webapp with Maven + Spring 5 + thymeleaf and, when I launch the following test:
MockHttpServletRequestBuilder createMessage = get(prueba/alta).secure(true)
.contentType(MediaType.TEXT_HTML);
this.mockMvc.perform(createMessage).andDo(print());
It returns the following error:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "ServletContext resource [/WEB-INF/views/templates/prueba/alta.html]") at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:986) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870) (....) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) ... 75 more Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/views/templates/prueba/alta.html] at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:159) at org.thymeleaf.spring5.templateresource.SpringResourceTemplateResource.reader(SpringResourceTemplateResource.java:103) at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:223) ... 87 more
However, if I run the application on tomcat 8, it works correctly. So, I guess the problem is that when you run the test, the test context does not "know" how to find the path I have defined to store the templates ( /WEB-INF/views/templates/
). How can I tell the test environment what the "path" is to /WEB-INF/views/templates/
?
If the problem is different, please correct me, because I'm a little lost.