-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Regression: SpringHandlerInstantiator breaks stand-alone support in the MVC Test framework [SPR-13375] #17957
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
Comments
Juergen Hoeller commented Hmm, we should consider a revision of Juergen |
Sam Brannen commented FYI: I updated my response on Stack Overflow. |
Sam Brannen commented Daniel Lynch, yes, you should be able to work around this issue by registering your own See my answer on the linked Stack Overflow discussion for details. Something like the following should work: ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
mockMvc = MockMvcBuilders.standaloneSetup(controller).setMessageConverters(new MappingJackson2HttpMessageConverter(objectMapper)).build(); Please let us know if that works for you! |
Sam Brannen commented Juergen Hoeller, agreed: a revision of |
Daniel Lynch commented Sam Brannen, thank you, your suggestion did work. |
Sam Brannen commented Daniel Lynch, great! We appreciate the feedback. |
Juergen Hoeller commented Sébastien Deleuze, I'll put this on my plate since it's really just about Juergen |
Sébastien Deleuze commented Juergen Hoeller Feel free to have a look to this repro project and reuse this commit not yet merged in master if you think this is ok.
|
Sam Brannen opened SPR-13375 and commented
The
SpringHandlerInstantiator
introduced in #15394 always attempts to create new beans using itsAutowireCapableBeanFactory
. In the case of aStubWebApplicationContext
, however, this results in anUnsupportedOperationException
being thrown.This behavior breaks support for JSON serialization in conjunction with the default configuration of the
MockMvcBuilders.standaloneSetup()
support in the Spring MVC Test framework since it internally uses aStubWebApplicationContext
.See the linked discussion on Stack Overflow for details.
Analysis
The following code in
WebMvcConfigurationSupport.addDefaultHttpMessageConverters()
is what causes this behavior:The fact that it supplies the
ApplicationContext
results in aSpringHandlerInstantiator
being created inJackson2ObjectMapperBuilder.configure()
, even though aSpringHandlerInstantiator
makes no sense for the stand-alone test setup in MVC Test.Affects: 4.1.3
Reference URL: http://stackoverflow.com/questions/32101611/spring-mockmvc-unsupportedoperationexception-after-upgrading-to-new-spring-versi/32140898
Referenced from: commits spring-attic/spring-framework-issues@028ace9
Backported to: 4.1.8
0 votes, 6 watchers
The text was updated successfully, but these errors were encountered: