Polishing
This commit is contained in:
@@ -168,7 +168,7 @@ class ConfigurationClassBeanDefinitionReader {
|
||||
this.registry.registerBeanDefinition(definitionHolder.getBeanName(), definitionHolder.getBeanDefinition());
|
||||
configClass.setBeanName(configBeanName);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Registered bean definition for imported @Configuration class %s", configBeanName));
|
||||
logger.debug("Registered bean definition for imported class '" + configBeanName + "'");
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
@@ -30,16 +30,16 @@ import java.lang.annotation.Target;
|
||||
* one {@link Bean @Bean} method, as well as {@link ImportSelector} and
|
||||
* {@link ImportBeanDefinitionRegistrar} implementations.
|
||||
*
|
||||
* <p>{@code @Bean} definitions declared in imported {@code @Configuration} classes
|
||||
* should be accessed by using {@link org.springframework.beans.factory.annotation.Autowired @Autowired}
|
||||
* <p>{@code @Bean} definitions declared in imported {@code @Configuration} classes should be
|
||||
* accessed by using {@link org.springframework.beans.factory.annotation.Autowired @Autowired}
|
||||
* injection. Either the bean itself can be autowired, or the configuration class instance
|
||||
* declaring the bean can be autowired. The latter approach allows for explicit,
|
||||
* IDE-friendly navigation between {@code @Configuration} class methods.
|
||||
* declaring the bean can be autowired. The latter approach allows for explicit, IDE-friendly
|
||||
* navigation between {@code @Configuration} class methods.
|
||||
*
|
||||
* <p>May be declared at the class level or as a meta-annotation.
|
||||
*
|
||||
* <p>If XML or other non-{@code @Configuration} bean definition resources need to be
|
||||
* imported, use {@link ImportResource @ImportResource}
|
||||
* imported, use the {@link ImportResource @ImportResource} annotation instead.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.0
|
||||
@@ -57,4 +57,5 @@ public @interface Import {
|
||||
* {@link ImportBeanDefinitionRegistrar} classes to import.
|
||||
*/
|
||||
Class<?>[] value();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -107,7 +107,6 @@ public class ContextLoader {
|
||||
/**
|
||||
* Config param for the root WebApplicationContext implementation class to use: {@value}
|
||||
* @see #determineContextClass(ServletContext)
|
||||
* @see #createWebApplicationContext(ServletContext, ApplicationContext)
|
||||
*/
|
||||
public static final String CONTEXT_CLASS_PARAM = "contextClass";
|
||||
|
||||
@@ -194,6 +193,7 @@ public class ContextLoader {
|
||||
*/
|
||||
private static volatile WebApplicationContext currentContext;
|
||||
|
||||
|
||||
/**
|
||||
* The root WebApplicationContext instance that this loader manages.
|
||||
*/
|
||||
@@ -360,6 +360,37 @@ public class ContextLoader {
|
||||
return (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the WebApplicationContext implementation class to use, either the
|
||||
* default XmlWebApplicationContext or a custom context class if specified.
|
||||
* @param servletContext current servlet context
|
||||
* @return the WebApplicationContext implementation class to use
|
||||
* @see #CONTEXT_CLASS_PARAM
|
||||
* @see org.springframework.web.context.support.XmlWebApplicationContext
|
||||
*/
|
||||
protected Class<?> determineContextClass(ServletContext servletContext) {
|
||||
String contextClassName = servletContext.getInitParameter(CONTEXT_CLASS_PARAM);
|
||||
if (contextClassName != null) {
|
||||
try {
|
||||
return ClassUtils.forName(contextClassName, ClassUtils.getDefaultClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
throw new ApplicationContextException(
|
||||
"Failed to load custom context class [" + contextClassName + "]", ex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
contextClassName = defaultStrategies.getProperty(WebApplicationContext.class.getName());
|
||||
try {
|
||||
return ClassUtils.forName(contextClassName, ContextLoader.class.getClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
throw new ApplicationContextException(
|
||||
"Failed to load default context class [" + contextClassName + "]", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated as of Spring 3.1 in favor of
|
||||
* {@link #createWebApplicationContext(ServletContext)} and
|
||||
@@ -417,7 +448,6 @@ public class ContextLoader {
|
||||
* org.springframework.core.annotation.Order Order} will be sorted appropriately.
|
||||
* @param sc the current servlet context
|
||||
* @param wac the newly created application context
|
||||
* @see #createWebApplicationContext(ServletContext, ApplicationContext)
|
||||
* @see #CONTEXT_INITIALIZER_CLASSES_PARAM
|
||||
* @see ApplicationContextInitializer#initialize(ConfigurableApplicationContext)
|
||||
*/
|
||||
@@ -451,37 +481,6 @@ public class ContextLoader {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the WebApplicationContext implementation class to use, either the
|
||||
* default XmlWebApplicationContext or a custom context class if specified.
|
||||
* @param servletContext current servlet context
|
||||
* @return the WebApplicationContext implementation class to use
|
||||
* @see #CONTEXT_CLASS_PARAM
|
||||
* @see org.springframework.web.context.support.XmlWebApplicationContext
|
||||
*/
|
||||
protected Class<?> determineContextClass(ServletContext servletContext) {
|
||||
String contextClassName = servletContext.getInitParameter(CONTEXT_CLASS_PARAM);
|
||||
if (contextClassName != null) {
|
||||
try {
|
||||
return ClassUtils.forName(contextClassName, ClassUtils.getDefaultClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
throw new ApplicationContextException(
|
||||
"Failed to load custom context class [" + contextClassName + "]", ex);
|
||||
}
|
||||
}
|
||||
else {
|
||||
contextClassName = defaultStrategies.getProperty(WebApplicationContext.class.getName());
|
||||
try {
|
||||
return ClassUtils.forName(contextClassName, ContextLoader.class.getClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
throw new ApplicationContextException(
|
||||
"Failed to load default context class [" + contextClassName + "]", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link ApplicationContextInitializer} implementation classes to use
|
||||
* if any have been specified by {@link #CONTEXT_INITIALIZER_CLASSES_PARAM}.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -23,14 +23,13 @@ import javax.servlet.ServletContextListener;
|
||||
* Bootstrap listener to start up and shut down Spring's root {@link WebApplicationContext}.
|
||||
* Simply delegates to {@link ContextLoader} as well as to {@link ContextCleanupListener}.
|
||||
*
|
||||
* <p>This listener should be registered after
|
||||
* {@link org.springframework.web.util.Log4jConfigListener}
|
||||
* <p>This listener should be registered after {@link org.springframework.web.util.Log4jConfigListener}
|
||||
* in {@code web.xml}, if the latter is used.
|
||||
*
|
||||
* <p>As of Spring 3.1, {@code ContextLoaderListener} supports injecting the root web
|
||||
* application context via the {@link #ContextLoaderListener(WebApplicationContext)}
|
||||
* constructor, allowing for programmatic configuration in Servlet 3.0+ environments. See
|
||||
* {@link org.springframework.web.WebApplicationInitializer} for usage examples.
|
||||
* constructor, allowing for programmatic configuration in Servlet 3.0+ environments.
|
||||
* See {@link org.springframework.web.WebApplicationInitializer} for usage examples.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
@@ -98,6 +97,7 @@ public class ContextLoaderListener extends ContextLoader implements ServletConte
|
||||
super(context);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize the root web application context.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
@@ -232,7 +232,7 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator
|
||||
* having a chance to resolve an argument value before the standard
|
||||
* argument handling kicks in.
|
||||
*/
|
||||
public void setCustomArgumentResolvers(WebArgumentResolver[] argumentResolvers) {
|
||||
public void setCustomArgumentResolvers(WebArgumentResolver... argumentResolvers) {
|
||||
this.customArgumentResolvers = argumentResolvers;
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator
|
||||
* Any such custom ModelAndViewResolver will kick in first, having a chance to
|
||||
* resolve an return value before the standard ModelAndView handling kicks in.
|
||||
*/
|
||||
public void setCustomModelAndViewResolvers(ModelAndViewResolver[] customModelAndViewResolvers) {
|
||||
public void setCustomModelAndViewResolvers(ModelAndViewResolver... customModelAndViewResolvers) {
|
||||
this.customModelAndViewResolvers = customModelAndViewResolvers;
|
||||
}
|
||||
|
||||
@@ -381,7 +381,8 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator
|
||||
if (response instanceof EventResponse) {
|
||||
// Update the existing model, if any, when responding to an event -
|
||||
// whereas we're replacing the model in case of an action response.
|
||||
Map<String, Object> existingModel = (Map<String, Object>) request.getPortletSession().getAttribute(IMPLICIT_MODEL_SESSION_ATTRIBUTE);
|
||||
Map<String, Object> existingModel = (Map<String, Object>)
|
||||
request.getPortletSession().getAttribute(IMPLICIT_MODEL_SESSION_ATTRIBUTE);
|
||||
if (existingModel != null) {
|
||||
existingModel.putAll(implicitModel);
|
||||
modelToStore = existingModel;
|
||||
@@ -812,9 +813,9 @@ public class AnnotationMethodHandlerAdapter extends PortletContentGenerator
|
||||
}
|
||||
}
|
||||
}
|
||||
return PortletAnnotationMappingUtils.checkRequestMethod(this.methods, request) &&
|
||||
return (PortletAnnotationMappingUtils.checkRequestMethod(this.methods, request) &&
|
||||
PortletAnnotationMappingUtils.checkParameters(this.params, request) &&
|
||||
PortletAnnotationMappingUtils.checkHeaders(this.headers, request);
|
||||
PortletAnnotationMappingUtils.checkHeaders(this.headers, request));
|
||||
}
|
||||
|
||||
public boolean isBetterMatchThan(RequestMappingInfo other) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -19,6 +19,7 @@ package org.springframework.web.servlet;
|
||||
import java.io.IOException;
|
||||
import java.security.Principal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletException;
|
||||
@@ -182,7 +183,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
|
||||
private String contextConfigLocation;
|
||||
|
||||
/** Actual ApplicationContextInitializer instances to apply to the context */
|
||||
private final ArrayList<ApplicationContextInitializer<ConfigurableApplicationContext>> contextInitializers =
|
||||
private final List<ApplicationContextInitializer<ConfigurableApplicationContext>> contextInitializers =
|
||||
new ArrayList<ApplicationContextInitializer<ConfigurableApplicationContext>>();
|
||||
|
||||
/** Comma-delimited ApplicationContextInitializer class names set through init param */
|
||||
@@ -364,12 +365,12 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic
|
||||
/**
|
||||
* Specify which {@link ApplicationContextInitializer} instances should be used
|
||||
* to initialize the application context used by this {@code FrameworkServlet}.
|
||||
* @see #configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext)
|
||||
* @see #applyInitializers(ConfigurableApplicationContext)
|
||||
* @see #configureAndRefreshWebApplicationContext
|
||||
* @see #applyInitializers
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setContextInitializers(ApplicationContextInitializer<? extends ConfigurableApplicationContext>... contextInitializers) {
|
||||
for (ApplicationContextInitializer<? extends ConfigurableApplicationContext> initializer : contextInitializers) {
|
||||
public void setContextInitializers(ApplicationContextInitializer<? extends ConfigurableApplicationContext>... initializers) {
|
||||
for (ApplicationContextInitializer<? extends ConfigurableApplicationContext> initializer : initializers) {
|
||||
this.contextInitializers.add((ApplicationContextInitializer<ConfigurableApplicationContext>) initializer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
@@ -334,7 +334,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||
* <p>Any such custom WebArgumentResolver will kick in first, having a chance to resolve
|
||||
* an argument value before the standard argument handling kicks in.
|
||||
*/
|
||||
public void setCustomArgumentResolvers(WebArgumentResolver[] argumentResolvers) {
|
||||
public void setCustomArgumentResolvers(WebArgumentResolver... argumentResolvers) {
|
||||
this.customArgumentResolvers = argumentResolvers;
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||
* <p>Any such custom ModelAndViewResolver will kick in first, having a chance to resolve
|
||||
* a return value before the standard ModelAndView handling kicks in.
|
||||
*/
|
||||
public void setCustomModelAndViewResolvers(ModelAndViewResolver[] customModelAndViewResolvers) {
|
||||
public void setCustomModelAndViewResolvers(ModelAndViewResolver... customModelAndViewResolvers) {
|
||||
this.customModelAndViewResolvers = customModelAndViewResolvers;
|
||||
}
|
||||
|
||||
@@ -929,7 +929,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||
// to be picked up by the RedirectView
|
||||
webRequest.getRequest().setAttribute(View.RESPONSE_STATUS_ATTRIBUTE, responseStatus);
|
||||
|
||||
responseArgumentUsed = true;
|
||||
this.responseArgumentUsed = true;
|
||||
}
|
||||
|
||||
// Invoke custom resolvers if present...
|
||||
@@ -992,8 +992,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||
}
|
||||
}
|
||||
|
||||
private void handleResponseBody(Object returnValue, ServletWebRequest webRequest)
|
||||
throws Exception {
|
||||
private void handleResponseBody(Object returnValue, ServletWebRequest webRequest) throws Exception {
|
||||
if (returnValue == null) {
|
||||
return;
|
||||
}
|
||||
@@ -1002,8 +1001,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||
writeWithMessageConverters(returnValue, inputMessage, outputMessage);
|
||||
}
|
||||
|
||||
private void handleHttpEntityResponse(HttpEntity<?> responseEntity, ServletWebRequest webRequest)
|
||||
throws Exception {
|
||||
private void handleHttpEntityResponse(HttpEntity<?> responseEntity, ServletWebRequest webRequest) throws Exception {
|
||||
if (responseEntity == null) {
|
||||
return;
|
||||
}
|
||||
@@ -1030,6 +1028,7 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||
private void writeWithMessageConverters(Object returnValue,
|
||||
HttpInputMessage inputMessage, HttpOutputMessage outputMessage)
|
||||
throws IOException, HttpMediaTypeNotAcceptableException {
|
||||
|
||||
List<MediaType> acceptedMediaTypes = inputMessage.getHeaders().getAccept();
|
||||
if (acceptedMediaTypes.isEmpty()) {
|
||||
acceptedMediaTypes = Collections.singletonList(MediaType.ALL);
|
||||
@@ -1061,7 +1060,6 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||
}
|
||||
throw new HttpMediaTypeNotAcceptableException(allSupportedMediaTypes);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1079,30 +1077,30 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||
private final String[] headers;
|
||||
|
||||
RequestMappingInfo(String[] patterns, RequestMethod[] methods, String[] params, String[] headers) {
|
||||
this.patterns = patterns != null ? patterns : new String[0];
|
||||
this.methods = methods != null ? methods : new RequestMethod[0];
|
||||
this.params = params != null ? params : new String[0];
|
||||
this.headers = headers != null ? headers : new String[0];
|
||||
this.patterns = (patterns != null ? patterns : new String[0]);
|
||||
this.methods = (methods != null ? methods : new RequestMethod[0]);
|
||||
this.params = (params != null ? params : new String[0]);
|
||||
this.headers = (headers != null ? headers : new String[0]);
|
||||
}
|
||||
|
||||
public boolean hasPatterns() {
|
||||
return patterns.length > 0;
|
||||
return (this.patterns.length > 0);
|
||||
}
|
||||
|
||||
public String[] getPatterns() {
|
||||
return patterns;
|
||||
return this.patterns;
|
||||
}
|
||||
|
||||
public int getMethodCount() {
|
||||
return methods.length;
|
||||
return this.methods.length;
|
||||
}
|
||||
|
||||
public int getParamCount() {
|
||||
return params.length;
|
||||
return this.params.length;
|
||||
}
|
||||
|
||||
public int getHeaderCount() {
|
||||
return headers.length;
|
||||
return this.headers.length;
|
||||
}
|
||||
|
||||
public boolean matches(HttpServletRequest request) {
|
||||
@@ -1122,8 +1120,8 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||
}
|
||||
|
||||
public Set<String> methodNames() {
|
||||
Set<String> methodNames = new LinkedHashSet<String>(methods.length);
|
||||
for (RequestMethod method : methods) {
|
||||
Set<String> methodNames = new LinkedHashSet<String>(this.methods.length);
|
||||
for (RequestMethod method : this.methods) {
|
||||
methodNames.add(method.name());
|
||||
}
|
||||
return methodNames;
|
||||
@@ -1145,18 +1143,18 @@ public class AnnotationMethodHandlerAdapter extends WebContentGenerator
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(Arrays.asList(patterns));
|
||||
if (methods.length > 0) {
|
||||
builder.append(Arrays.asList(this.patterns));
|
||||
if (this.methods.length > 0) {
|
||||
builder.append(',');
|
||||
builder.append(Arrays.asList(methods));
|
||||
builder.append(Arrays.asList(this.methods));
|
||||
}
|
||||
if (headers.length > 0) {
|
||||
if (this.headers.length > 0) {
|
||||
builder.append(',');
|
||||
builder.append(Arrays.asList(headers));
|
||||
builder.append(Arrays.asList(this.headers));
|
||||
}
|
||||
if (params.length > 0) {
|
||||
if (this.params.length > 0) {
|
||||
builder.append(',');
|
||||
builder.append(Arrays.asList(params));
|
||||
builder.append(Arrays.asList(this.params));
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -64,7 +64,6 @@ public abstract class AbstractDispatcherServletInitializer extends AbstractConte
|
||||
@Override
|
||||
public void onStartup(ServletContext servletContext) throws ServletException {
|
||||
super.onStartup(servletContext);
|
||||
|
||||
registerDispatcherServlet(servletContext);
|
||||
}
|
||||
|
||||
@@ -80,7 +79,7 @@ public abstract class AbstractDispatcherServletInitializer extends AbstractConte
|
||||
*/
|
||||
protected void registerDispatcherServlet(ServletContext servletContext) {
|
||||
String servletName = getServletName();
|
||||
Assert.hasLength(servletName, "getServletName() may not return empty or null");
|
||||
Assert.hasLength(servletName, "getServletName() must not return empty or null");
|
||||
|
||||
WebApplicationContext servletAppContext = createServletApplicationContext();
|
||||
Assert.notNull(servletAppContext,
|
||||
@@ -178,9 +177,9 @@ public abstract class AbstractDispatcherServletInitializer extends AbstractConte
|
||||
}
|
||||
|
||||
private EnumSet<DispatcherType> getDispatcherTypes() {
|
||||
return isAsyncSupported() ?
|
||||
EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.ASYNC) :
|
||||
EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE);
|
||||
return (isAsyncSupported() ?
|
||||
EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.ASYNC) :
|
||||
EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user