Proper location of Thymeleaf views for Spring -


i running spring boot application thymeleaf. when run application through ide (intellij) runs fine. however, when run application through command line (java -jar) views not resolve , following error:

org.thymeleaf.exceptions.templateinputexception: error resolving template "index", template might not exist or might not accessible of configured template resolvers     @ org.thymeleaf.templaterepository.gettemplate(templaterepository.java:245)     @ org.thymeleaf.templateengine.process(templateengine.java:1104)     @ org.thymeleaf.templateengine.process(templateengine.java:1060)     @ org.thymeleaf.templateengine.process(templateengine.java:1011)     @ org.thymeleaf.spring3.view.thymeleafview.renderfragment(thymeleafview.java:335)     @ org.thymeleaf.spring3.view.thymeleafview.render(thymeleafview.java:190)     @ org.springframework.web.servlet.dispatcherservlet.render(dispatcherservlet.java:1225)     @ org.springframework.web.servlet.dispatcherservlet.processdispatchresult(dispatcherservlet.java:1012)     @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:959) 

here settings:

my directory structure

project-root   --src     --main       --java         --controllers           --[class main method]         --views           --index.html 

my template resolver:

@bean   public viewresolver viewresolver() {     classloadertemplateresolver templateresolver = new classloadertemplateresolver();     templateresolver.settemplatemode("xhtml");     templateresolver.setprefix("views/");     templateresolver.setsuffix(".html");     springtemplateengine engine = new springtemplateengine();     engine.settemplateresolver(templateresolver);      thymeleafviewresolver viewresolver = new thymeleafviewresolver();     viewresolver.settemplateengine(engine);     return viewresolver;   } 

where should put views can correctly resolved when ran jar file?

i think answer depends on build configuration. directory "src/main/views" not standard resource location common build tool, have explicitly add configuration of tool use build jar.

if go flow (why different?), , use "src/main/resources" classpath resources. leave out thymeleaf configuration , let spring boot handle it, putting templates in "src/main/resources/templates".


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -