-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
Sam Brannen opened SPR-13375 and commented
The SpringHandlerInstantiator
introduced in #15394 always attempts to create new beans using its AutowireCapableBeanFactory
. In the case of a StubWebApplicationContext
, however, this results in an UnsupportedOperationException
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 a StubWebApplicationContext
.
See the linked discussion on Stack Overflow for details.
Analysis
The following code in WebMvcConfigurationSupport.addDefaultHttpMessageConverters()
is what causes this behavior:
if (jackson2Present) {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().applicationContext(this.applicationContext).build();
messageConverters.add(new MappingJackson2HttpMessageConverter(objectMapper));
}
The fact that it supplies the ApplicationContext
results in a SpringHandlerInstantiator
being created in Jackson2ObjectMapperBuilder.configure()
, even though a SpringHandlerInstantiator
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