4

My app works just fine if I run the application on my host using the

mvn spring-boot:run 

but when I deploy it on docker, it does not work and I get this error:

SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/store/index", template might not exist or might not be accessible by any of the configured Template Resolvers] with root cause org.thymeleaf.exceptions.TemplateInputException: Error resolving template "/store/index", template might not exist or might not be accessible by any of the configured Template Resolvers

but if I go on the url: http:localhost:8080/login which is controlled by spring security, renders the template normally. Seems to be a permission problem but I'm not sure.

here is my Dockerfile:

FROM openjdk VOLUME /tmp RUN touch engdevcommerce.jar COPY target/engdevcommerce.jar engdevcommerce.jar ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/engdevcommerce.jar"] 

Solution: Turns out the problem I was having, had nothing to do with the docker deployment. I ran the jar file on my host, and I was getting the same error. The problem was that, where I returned the view url at the controllers methods, I was starting with slash like this: "/.../..." . And spring does not load view with double slash when the application is packed as .jar file. I had to remove the slash character at the beginning of the url every where I returned a ModelAndView and at the th:insert tags too on my html files.

this link helped me a lot : spring-boot-thymeleaf-not-resolving-fragments-after-packaging

2
  • in your local do you have /store/index ? Commented Sep 1, 2018 at 18:18
  • Yes, the files are inside of the jar, and if I run the jar locally on my host, it works ok. I'll try to add the directory to my Dockerfile as soon as I'm back home and I'll let you know if it works. Thank you. Commented Sep 1, 2018 at 19:19

2 Answers 2

1

Always check the application execution first with 'java -jar your_app_name.jar' command! In general this issue is mostly resolved by checking following 3 points-

  1. Your application.properties should have the entry- spring.thymeleaf.prefix=classpath:/templates/
  2. Your controller should return name of the template without any preceding slash. As the thymeleaf configuration is case sensitive.
  3. Your Project should follow standard spring boot thymeleaf directory structure. If not, then make changes accordingly in your application.properties file.
Sign up to request clarification or add additional context in comments.

Comments

0

add your local index directory to dockerfile so it will create /store and copy the index directory to /store then your docker vm will have /store/index with the contents from you local index directory

 ... ... ADD <local-index-directory> /store ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","- jar","/engdevcommerce.jar"] 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.