1
1
/*
2
- * Copyright 2002-2013 the original author or authors.
2
+ * Copyright 2002-2014 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
package org .springframework .web .servlet .support ;
18
18
19
19
import java .util .EnumSet ;
20
-
21
20
import javax .servlet .DispatcherType ;
22
21
import javax .servlet .Filter ;
23
22
import javax .servlet .FilterRegistration ;
34
33
import org .springframework .web .servlet .DispatcherServlet ;
35
34
36
35
/**
37
- * Base class for {@link org.springframework.web.WebApplicationInitializer
38
- * WebApplicationInitializer} implementations that register a {@link DispatcherServlet} in
39
- * the servlet context.
36
+ * Base class for {@link org.springframework.web.WebApplicationInitializer}
37
+ * implementations that register a {@link DispatcherServlet} in the servlet context.
40
38
*
41
- * <p>Concrete implementations are required to implement {@link
42
- * #createServletApplicationContext()}, as well as {@link #getServletMappings()}, both of
43
- * which get invoked from {@link #registerDispatcherServlet(ServletContext)}. Further
44
- * customization can be achieved by overriding
39
+ * <p>Concrete implementations are required to implement
40
+ * {@link #createServletApplicationContext()}, as well as {@link #getServletMappings()},
41
+ * both of which get invoked from {@link #registerDispatcherServlet(ServletContext)}.
42
+ * Further customization can be achieved by overriding
45
43
* {@link #customizeRegistration(ServletRegistration.Dynamic)}.
46
44
*
47
45
* <p>Because this class extends from {@link AbstractContextLoaderInitializer}, concrete
55
53
* @author Rossen Stoyanchev
56
54
* @since 3.2
57
55
*/
58
- public abstract class AbstractDispatcherServletInitializer
59
- extends AbstractContextLoaderInitializer {
56
+ public abstract class AbstractDispatcherServletInitializer extends AbstractContextLoaderInitializer {
60
57
61
58
/**
62
59
* The default servlet name. Can be customized by overriding {@link #getServletName}.
63
60
*/
64
61
public static final String DEFAULT_SERVLET_NAME = "dispatcher" ;
65
62
63
+
66
64
@ Override
67
65
public void onStartup (ServletContext servletContext ) throws ServletException {
68
66
super .onStartup (servletContext );
69
67
70
- this . registerDispatcherServlet (servletContext );
68
+ registerDispatcherServlet (servletContext );
71
69
}
72
70
73
71
/**
74
72
* Register a {@link DispatcherServlet} against the given servlet context.
75
- * <p>This method will create a {@code DispatcherServlet} with the name returned from
73
+ * <p>This method will create a {@code DispatcherServlet} with the name returned by
76
74
* {@link #getServletName()}, initializing it with the application context returned
77
75
* from {@link #createServletApplicationContext()}, and mapping it to the patterns
78
76
* returned from {@link #getServletMappings()}.
@@ -81,21 +79,18 @@ public void onStartup(ServletContext servletContext) throws ServletException {
81
79
* @param servletContext the context to register the servlet against
82
80
*/
83
81
protected void registerDispatcherServlet (ServletContext servletContext ) {
84
- String servletName = this . getServletName ();
82
+ String servletName = getServletName ();
85
83
Assert .hasLength (servletName , "getServletName() may not return empty or null" );
86
84
87
- WebApplicationContext servletAppContext = this . createServletApplicationContext ();
85
+ WebApplicationContext servletAppContext = createServletApplicationContext ();
88
86
Assert .notNull (servletAppContext ,
89
87
"createServletApplicationContext() did not return an application " +
90
- "context for servlet [" + servletName + "]" );
88
+ "context for servlet [" + servletName + "]" );
91
89
92
90
DispatcherServlet dispatcherServlet = new DispatcherServlet (servletAppContext );
93
-
94
- ServletRegistration .Dynamic registration =
95
- servletContext .addServlet (servletName , dispatcherServlet );
96
-
91
+ ServletRegistration .Dynamic registration = servletContext .addServlet (servletName , dispatcherServlet );
97
92
Assert .notNull (registration ,
98
- "Failed to register servlet with name '" + servletName + "'. " +
93
+ "Failed to register servlet with name '" + servletName + "'." +
99
94
"Check if there is another servlet registered under the same name." );
100
95
101
96
registration .setLoadOnStartup (1 );
@@ -109,7 +104,7 @@ protected void registerDispatcherServlet(ServletContext servletContext) {
109
104
}
110
105
}
111
106
112
- this . customizeRegistration (registration );
107
+ customizeRegistration (registration );
113
108
}
114
109
115
110
/**
@@ -124,8 +119,8 @@ protected String getServletName() {
124
119
/**
125
120
* Create a servlet application context to be provided to the {@code DispatcherServlet}.
126
121
* <p>The returned context is delegated to Spring's
127
- * {@link DispatcherServlet#DispatcherServlet(WebApplicationContext)}. As such, it
128
- * typically contains controllers, view resolvers, locale resolvers, and other
122
+ * {@link DispatcherServlet#DispatcherServlet(WebApplicationContext)}. As such,
123
+ * it typically contains controllers, view resolvers, locale resolvers, and other
129
124
* web-related beans.
130
125
* @see #registerDispatcherServlet(ServletContext)
131
126
*/
@@ -140,7 +135,6 @@ protected String getServletName() {
140
135
141
136
/**
142
137
* Specify filters to add and map to the {@code DispatcherServlet}.
143
- *
144
138
* @return an array of filters or {@code null}
145
139
* @see #registerServletFilter(ServletContext, Filter)
146
140
*/
@@ -161,7 +155,6 @@ protected Filter[] getServletFilters() {
161
155
* </ul>
162
156
* <p>If the above defaults are not suitable or insufficient, override this
163
157
* method and register filters directly with the {@code ServletContext}.
164
- *
165
158
* @param servletContext the servlet context to register filters with
166
159
* @param filter the filter to be registered
167
160
* @return the filter registration
0 commit comments