Browse Source

Polishing

Issue: SPR-11357
pull/465/head
Juergen Hoeller 12 years ago
parent
commit
341d645d09
  1. 9
      spring-web/src/main/java/org/springframework/web/context/AbstractContextLoaderInitializer.java
  2. 19
      spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractDispatcherServletInitializer.java

9
spring-web/src/main/java/org/springframework/web/context/AbstractContextLoaderInitializer.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
@ -38,11 +38,12 @@ import org.springframework.web.WebApplicationInitializer; @@ -38,11 +38,12 @@ import org.springframework.web.WebApplicationInitializer;
*/
public abstract class AbstractContextLoaderInitializer implements WebApplicationInitializer {
/** Logger available to subclasses. */
/** Logger available to subclasses */
protected final Log logger = LogFactory.getLog(getClass());
public void onStartup(ServletContext servletContext) throws ServletException {
this.registerContextLoaderListener(servletContext);
registerContextLoaderListener(servletContext);
}
/**
@ -52,7 +53,7 @@ public abstract class AbstractContextLoaderInitializer implements WebApplication @@ -52,7 +53,7 @@ public abstract class AbstractContextLoaderInitializer implements WebApplication
* @param servletContext the servlet context to register the listener against
*/
protected void registerContextLoaderListener(ServletContext servletContext) {
WebApplicationContext rootAppContext = this.createRootApplicationContext();
WebApplicationContext rootAppContext = createRootApplicationContext();
if (rootAppContext != null) {
servletContext.addListener(new ContextLoaderListener(rootAppContext));
}

19
spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractDispatcherServletInitializer.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
@ -17,7 +17,6 @@ @@ -17,7 +17,6 @@
package org.springframework.web.servlet.support;
import java.util.EnumSet;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterRegistration;
@ -55,19 +54,19 @@ import org.springframework.web.servlet.DispatcherServlet; @@ -55,19 +54,19 @@ import org.springframework.web.servlet.DispatcherServlet;
* @author Rossen Stoyanchev
* @since 3.2
*/
public abstract class AbstractDispatcherServletInitializer
extends AbstractContextLoaderInitializer {
public abstract class AbstractDispatcherServletInitializer extends AbstractContextLoaderInitializer {
/**
* The default servlet name. Can be customized by overriding {@link #getServletName}.
*/
public static final String DEFAULT_SERVLET_NAME = "dispatcher";
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
this.registerDispatcherServlet(servletContext);
registerDispatcherServlet(servletContext);
}
/**
@ -82,19 +81,15 @@ public abstract class AbstractDispatcherServletInitializer @@ -82,19 +81,15 @@ public abstract class AbstractDispatcherServletInitializer
*/
protected void registerDispatcherServlet(ServletContext servletContext) {
String servletName = this.getServletName();
Assert.hasLength(servletName,
"getServletName() may not return empty or null");
Assert.hasLength(servletName, "getServletName() may not return empty or null");
WebApplicationContext servletAppContext = this.createServletApplicationContext();
Assert.notNull(servletAppContext,
"createServletApplicationContext() did not return an application " +
"context for servlet [" + servletName + "]");
"context for servlet [" + servletName + "]");
DispatcherServlet dispatcherServlet = new DispatcherServlet(servletAppContext);
ServletRegistration.Dynamic registration =
servletContext.addServlet(servletName, dispatcherServlet);
ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, dispatcherServlet);
Assert.notNull(registration,
"Failed to register servlet with name '" + servletName + "'." +
"Check if there is another servlet registered under the same name.");

Loading…
Cancel
Save