Skip to content

Commit 2700993

Browse files
committed
Add protected method in StandaloneMockMvcBuilder
To allow sub-classes to register additional MVC infrastructure. Issue: SPR-17520
1 parent 0ad3505 commit 2700993

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ private void registerMvcSingletons(StubWebApplicationContext wac) {
399399

400400
this.flashMapManager = new SessionFlashMapManager();
401401
wac.addBean(DispatcherServlet.FLASH_MAP_MANAGER_BEAN_NAME, this.flashMapManager);
402+
403+
extendMvcSingletons(sc).forEach(wac::addBean);
402404
}
403405

404406
private List<ViewResolver> initViewResolvers(WebApplicationContext wac) {
@@ -412,6 +414,18 @@ private List<ViewResolver> initViewResolvers(WebApplicationContext wac) {
412414
return this.viewResolvers;
413415
}
414416

417+
/**
418+
* This method could be used from a sub-class to register additional Spring
419+
* MVC infrastructure such as additional {@code HandlerMapping},
420+
* {@code HandlerAdapter}, and others.
421+
* @param servletContext the ServletContext
422+
* @return a map with additional MVC infrastructure object instances
423+
* @since 5.1.4
424+
*/
425+
protected Map<String, Object> extendMvcSingletons(@Nullable ServletContext servletContext) {
426+
return Collections.emptyMap();
427+
}
428+
415429

416430
/** Using the MVC Java configuration as the starting point for the "standalone" setup. */
417431
private class StandaloneConfiguration extends WebMvcConfigurationSupport {

0 commit comments

Comments
 (0)