Add createDispatcherServlet hook point

Add an extra hook point in `AbstractDispatcherServletInitializer` to
customize the `DispatcherServlet`.

Issue: SPR-13222
This commit is contained in:
Stephane Nicoll
2015-07-13 14:43:06 +02:00
parent 84138abfd1
commit d738dddd8f
4 changed files with 32 additions and 6 deletions

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -70,6 +70,7 @@ public class DispatcherServletInitializerTests {
assertNotNull(servlets.get(SERVLET_NAME));
DispatcherServlet servlet = (DispatcherServlet) servlets.get(SERVLET_NAME);
assertEquals(MyDispatcherServlet.class, servlet.getClass());
WebApplicationContext servletContext = servlet.getWebApplicationContext();
assertTrue(servletContext.containsBean("bean"));
@@ -84,6 +85,7 @@ public class DispatcherServletInitializerTests {
assertEquals(ROLE_NAME, registration.getRunAsRole());
}
private class MyMockServletContext extends MockServletContext {
@Override
@@ -104,6 +106,11 @@ public class DispatcherServletInitializerTests {
return SERVLET_NAME;
}
@Override
protected DispatcherServlet createDispatcherServlet(WebApplicationContext servletAppContext) {
return new MyDispatcherServlet(servletAppContext);
}
@Override
protected WebApplicationContext createServletApplicationContext() {
StaticWebApplicationContext servletContext =
@@ -129,7 +136,12 @@ public class DispatcherServletInitializerTests {
}
private static class MyBean {
}
private static class MyDispatcherServlet extends DispatcherServlet {
public MyDispatcherServlet(WebApplicationContext webApplicationContext) {
super(webApplicationContext);
}
}
}