Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThymeleafViewResolver doesn't play nice with MockMvc #85

Closed
chrylis opened this issue May 4, 2015 · 2 comments
Closed

ThymeleafViewResolver doesn't play nice with MockMvc #85

chrylis opened this issue May 4, 2015 · 2 comments

Comments

@chrylis
Copy link

chrylis commented May 4, 2015

The ThymeleafViewResolver appears to treat views as self-contained beans, and at line 661 it calls beanFactory.autowireBeanProperties on them. This causes an exception when attempting to use the view resolver with a standalone MockMvc context, which is a stub context and doesn't support autowiring:

Caused by: java.lang.UnsupportedOperationException
at org.springframework.test.web.servlet.setup.StubWebApplicationContext$StubBeanFactory.autowireBeanProperties(StubWebApplicationContext.java:365)
at org.thymeleaf.spring4.view.ThymeleafViewResolver.loadView(ThymeleafViewResolver.java:661)
at org.thymeleaf.spring4.view.ThymeleafViewResolver.createView(ThymeleafViewResolver.java:626)
at org.springframework.web.servlet.view.AbstractCachingViewResolver.resolveViewName(AbstractCachingViewResolver.java:156)
at org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1283)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1224)
at org.springframework.test.web.servlet.TestDispatcherServlet.render(TestDispatcherServlet.java:105)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
... 22 more

This is triggered from this MockMvc setup:

MockMvcBuilders.standaloneSetup(new StaticPagesHtmlController()).setViewResolvers(new ThymeleafViewResolver()).build()

Is there any simple way to render Thymeleaf views with a MockMvc standalone setup?

@jeanbza
Copy link

jeanbza commented Sep 21, 2015

+1, also would like to see this resolved (thymeleaf+mockmvc)

@danielfernandez
Copy link
Member

This behaviour seems to have been fixed in the Spring MVC Test framework itself, and now StubWebApplicationContext$StubBeanFactory.autowireBeanProperties(...) does not raise an UnsupportedOperationException anymore.

Check out SPR-13375: https://jira.spring.io/browse/SPR-13375 fixed in versions 4.1.8 and 4.2.1 of Spring Framework.

And the relevant commit: spring-projects/spring-framework@7d30017

I'm therefore closing this. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants