diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java index b5926e7e3a..c51656d2d5 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java @@ -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 { diff --git a/spring-context/src/main/java/org/springframework/context/annotation/Import.java b/spring-context/src/main/java/org/springframework/context/annotation/Import.java index 6c03d55f69..a9eca05635 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/Import.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/Import.java @@ -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. * - *

{@code @Bean} definitions declared in imported {@code @Configuration} classes - * should be accessed by using {@link org.springframework.beans.factory.annotation.Autowired @Autowired} + *

{@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. * *

May be declared at the class level or as a meta-annotation. * *

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(); + } diff --git a/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java b/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java index 16da9161d3..1edc6336c2 100644 --- a/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java +++ b/spring-web/src/main/java/org/springframework/web/context/ContextLoader.java @@ -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}. diff --git a/spring-web/src/main/java/org/springframework/web/context/ContextLoaderListener.java b/spring-web/src/main/java/org/springframework/web/context/ContextLoaderListener.java index 83aff2d3de..42bcd77f1c 100644 --- a/spring-web/src/main/java/org/springframework/web/context/ContextLoaderListener.java +++ b/spring-web/src/main/java/org/springframework/web/context/ContextLoaderListener.java @@ -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}. * - *

This listener should be registered after - * {@link org.springframework.web.util.Log4jConfigListener} + *

This listener should be registered after {@link org.springframework.web.util.Log4jConfigListener} * in {@code web.xml}, if the latter is used. * *

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. */ diff --git a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java index 528f83328b..31ac98086e 100644 --- a/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java +++ b/spring-webmvc-portlet/src/main/java/org/springframework/web/portlet/mvc/annotation/AnnotationMethodHandlerAdapter.java @@ -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 existingModel = (Map) request.getPortletSession().getAttribute(IMPLICIT_MODEL_SESSION_ATTRIBUTE); + Map existingModel = (Map) + 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) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java index 9256d0a8c8..610ecdf860 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/FrameworkServlet.java @@ -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> contextInitializers = + private final List> contextInitializers = new ArrayList>(); /** 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... contextInitializers) { - for (ApplicationContextInitializer initializer : contextInitializers) { + public void setContextInitializers(ApplicationContextInitializer... initializers) { + for (ApplicationContextInitializer initializer : initializers) { this.contextInitializers.add((ApplicationContextInitializer) initializer); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java index 6c071af07f..28cf8ce080 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/AnnotationMethodHandlerAdapter.java @@ -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 *

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 *

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 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 methodNames() { - Set methodNames = new LinkedHashSet(methods.length); - for (RequestMethod method : methods) { + Set methodNames = new LinkedHashSet(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(); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractDispatcherServletInitializer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractDispatcherServletInitializer.java index 2517b011d2..e7a969f927 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractDispatcherServletInitializer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractDispatcherServletInitializer.java @@ -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 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)); } /**