Issue with my Thymeleaf + Spring configuration

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Issue with my Thymeleaf + Spring configuration

balteo
Hello,

I have removed the Tiles configuration from my Spring project and added this Thymeleaf config:

        <bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
                <property name="prefix" value="/WEB-INF/templates/" />
                <property name="suffix" value=".html" />
                <property name="templateMode" value="HTML5" />
        </bean>

        <bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
                <property name="templateResolver" ref="templateResolver" />
        </bean>

        <bean id="viewResolver" class="org.thymeleaf.spring3.view.ThymeleafViewResolver">
                <property name="templateEngine" ref="templateEngine" />
                <property name="order" value="1" />
                <property name="viewNames" value="*.html,*.xhtml" />
        </bean>

I systematically get this exception:


javax.servlet.ServletException: Could not resolve view with name 'index' in servlet with name 'kadjoukor'
        org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1162)
        org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
        org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
        org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
        org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:147)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
        org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
        org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
        org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

Can anyone please help me getting started with Thymeleaf?

Regards,
J.
Reply | Threaded
Open this post in threaded view
|

Re: Issue with my Thymeleaf + Spring configuration

balteo
Note that I do have an index.html in my /WEB-INF/templates directory.
Reply | Threaded
Open this post in threaded view
|

Re: Issue with my Thymeleaf + Spring configuration

balteo
In reply to this post by balteo
Removing the following property:

 <property name="viewNames" value="*.html,*.xhtml" />

sorted the problem.
J.

P.S.
Thanks Daniel!
Reply | Threaded
Open this post in threaded view
|

Re: Issue with my Thymeleaf + Spring configuration

danielfernandez
Administrator
In reply to this post by balteo
The problem is you are telling your ViewResolver to only resolve views ending in "*.html", "*.xhtml", etc. by means of your "viewNames" property. And your view is called just "index".

Remember that the ".html" suffix is added by your template resolver, which means it is used to determine the name of the template file that corresponds to your view... once the ViewResolver has accepted resolving (and processing) it.

Regards,
Daniel