From fc629bb508f950fe4a0f62b42395299677f7819e Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Thu, 29 Dec 2016 22:39:36 +0100 Subject: [PATCH] Polishing --- .../autoproxy/AbstractAutoProxyCreator.java | 55 +++++++++---------- .../MergedBeanDefinitionPostProcessor.java | 18 +++--- .../ConfigurationClassPostProcessor.java | 5 -- .../config/JmsListenerEndpointRegistrar.java | 6 +- .../reactive/FlushingIntegrationTests.java | 5 +- ...NamespaceHandlerScopeIntegrationTests.java | 23 ++++---- 6 files changed, 52 insertions(+), 60 deletions(-) diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java index 03d4328c1ce..18abf346eef 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAutoProxyCreator.java @@ -55,26 +55,25 @@ import org.springframework.util.StringUtils; * before invoking the bean itself. * *

This class distinguishes between "common" interceptors: shared for all proxies it - * creates, and "specific" interceptors: unique per bean instance. There need not - * be any common interceptors. If there are, they are set using the interceptorNames - * property. As with ProxyFactoryBean, interceptors names in the current factory - * are used rather than bean references to allow correct handling of prototype - * advisors and interceptors: for example, to support stateful mixins. - * Any advice type is supported for "interceptorNames" entries. + * creates, and "specific" interceptors: unique per bean instance. There need not be any + * common interceptors. If there are, they are set using the interceptorNames property. + * As with {@link org.springframework.aop.framework.ProxyFactoryBean}, interceptors names + * in the current factory are used rather than bean references to allow correct handling + * of prototype advisors and interceptors: for example, to support stateful mixins. + * Any advice type is supported for {@link #setInterceptorNames "interceptorNames"} entries. * *

Such auto-proxying is particularly useful if there's a large number of beans that * need to be wrapped with similar proxies, i.e. delegating to the same interceptors. * Instead of x repetitive proxy definitions for x target beans, you can register * one single such post processor with the bean factory to achieve the same effect. * - *

Subclasses can apply any strategy to decide if a bean is to be proxied, - * e.g. by type, by name, by definition details, etc. They can also return - * additional interceptors that should just be applied to the specific bean - * instance. The default concrete implementation is BeanNameAutoProxyCreator, - * identifying the beans to be proxied via a list of bean names. + *

Subclasses can apply any strategy to decide if a bean is to be proxied, e.g. by type, + * by name, by definition details, etc. They can also return additional interceptors that + * should just be applied to the specific bean instance. A simple concrete implementation is + * {@link BeanNameAutoProxyCreator}, identifying the beans to be proxied via given names. * *

Any number of {@link TargetSourceCreator} implementations can be used to create - * a custom target source - for example, to pool prototype objects. Auto-proxying will + * a custom target source: for example, to pool prototype objects. Auto-proxying will * occur even if there is no advice, as long as a TargetSourceCreator specifies a custom * {@link org.springframework.aop.TargetSource}. If there are no TargetSourceCreators set, * or if none matches, a {@link org.springframework.aop.target.SingletonTargetSource} @@ -128,11 +127,9 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport private BeanFactory beanFactory; - private final Set targetSourcedBeans = - Collections.newSetFromMap(new ConcurrentHashMap<>(16)); + private final Set targetSourcedBeans = Collections.newSetFromMap(new ConcurrentHashMap<>(16)); - private final Set earlyProxyReferences = - Collections.newSetFromMap(new ConcurrentHashMap<>(16)); + private final Set earlyProxyReferences = Collections.newSetFromMap(new ConcurrentHashMap<>(16)); private final Map> proxyTypes = new ConcurrentHashMap<>(16); @@ -156,8 +153,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport } /** - * Specify the AdvisorAdapterRegistry to use. - * Default is the global AdvisorAdapterRegistry. + * Specify the {@link AdvisorAdapterRegistry} to use. + *

Default is the global {@link AdvisorAdapterRegistry}. * @see org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry */ public void setAdvisorAdapterRegistry(AdvisorAdapterRegistry advisorAdapterRegistry) { @@ -165,18 +162,18 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport } /** - * Set custom TargetSourceCreators to be applied in this order. - * If the list is empty, or they all return null, a SingletonTargetSource + * Set custom {@code TargetSourceCreators} to be applied in this order. + * If the list is empty, or they all return null, a {@link SingletonTargetSource} * will be created for each bean. *

Note that TargetSourceCreators will kick in even for target beans - * where no advices or advisors have been found. If a TargetSourceCreator - * returns a TargetSource for a specific bean, that bean will be proxied + * where no advices or advisors have been found. If a {@code TargetSourceCreator} + * returns a {@link TargetSource} for a specific bean, that bean will be proxied * in any case. - *

TargetSourceCreators can only be invoked if this post processor is used - * in a BeanFactory, and its BeanFactoryAware callback is used. - * @param targetSourceCreators list of TargetSourceCreator. - * Ordering is significant: The TargetSource returned from the first matching - * TargetSourceCreator (that is, the first that returns non-null) will be used. + *

{@code TargetSourceCreators} can only be invoked if this post processor is used + * in a {@link BeanFactory} and its {@link BeanFactoryAware} callback is triggered. + * @param targetSourceCreators the list of {@code TargetSourceCreators}. + * Ordering is significant: The {@code TargetSource} returned from the first matching + * {@code TargetSourceCreator} (that is, the first that returns non-null) will be used. */ public void setCustomTargetSourceCreators(TargetSourceCreator... targetSourceCreators) { this.customTargetSourceCreators = targetSourceCreators; @@ -207,8 +204,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport } /** - * Return the owning BeanFactory. - * May be {@code null}, as this object doesn't need to belong to a bean factory. + * Return the owning {@link BeanFactory}. + * May be {@code null}, as this post-processor doesn't need to belong to a bean factory. */ protected BeanFactory getBeanFactory() { return this.beanFactory; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/MergedBeanDefinitionPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/MergedBeanDefinitionPostProcessor.java index d9846442a9f..02d050aeadc 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/MergedBeanDefinitionPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/MergedBeanDefinitionPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2016 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. @@ -20,20 +20,20 @@ import org.springframework.beans.factory.config.BeanPostProcessor; /** * Post-processor callback interface for merged bean definitions at runtime. - * {@link BeanPostProcessor} implementations may implement this sub-interface in - * order to post-process the merged bean definition that the Spring BeanFactory - * uses to create a specific bean instance. + * {@link BeanPostProcessor} implementations may implement this sub-interface in order + * to post-process the merged bean definition (a processed copy of the original bean + * definition) that the Spring {@code BeanFactory} uses to create a bean instance. * *

The {@link #postProcessMergedBeanDefinition} method may for example introspect * the bean definition in order to prepare some cached metadata before post-processing - * actual instances of a bean. It is also allowed to modify the bean definition - * but only for bean definition properties which are actually intended - * for concurrent modification. Basically, this only applies to operations - * defined on the {@link RootBeanDefinition} itself but not to the properties - * of its base classes. + * actual instances of a bean. It is also allowed to modify the bean definition but + * only for definition properties which are actually intended for concurrent + * modification. Essentially, this only applies to operations defined on the + * {@link RootBeanDefinition} itself but not to the properties of its base classes. * * @author Juergen Hoeller * @since 2.5 + * @see org.springframework.beans.factory.config.ConfigurableBeanFactory#getMergedBeanDefinition */ public interface MergedBeanDefinitionPostProcessor extends BeanPostProcessor { diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java index 7c82cc02a1e..e5bab7aaeba 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java @@ -437,11 +437,6 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo } return bean; } - - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) { - return bean; - } } } diff --git a/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistrar.java b/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistrar.java index 26bf2cf041e..ad476e94905 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistrar.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerEndpointRegistrar.java @@ -28,8 +28,7 @@ import org.springframework.messaging.handler.annotation.support.MessageHandlerMe import org.springframework.util.Assert; /** - * Helper bean for registering {@link JmsListenerEndpoint} with - * a {@link JmsListenerEndpointRegistry}. + * Helper bean for registering {@link JmsListenerEndpoint} with a {@link JmsListenerEndpointRegistry}. * * @author Stephane Nicoll * @author Juergen Hoeller @@ -48,8 +47,7 @@ public class JmsListenerEndpointRegistrar implements BeanFactoryAware, Initializ private BeanFactory beanFactory; - private final List endpointDescriptors = - new ArrayList<>(); + private final List endpointDescriptors = new ArrayList<>(); private boolean startImmediately; diff --git a/spring-web-reactive/src/test/java/org/springframework/web/reactive/FlushingIntegrationTests.java b/spring-web-reactive/src/test/java/org/springframework/web/reactive/FlushingIntegrationTests.java index d9dd73e29c9..0f498ec74e1 100644 --- a/spring-web-reactive/src/test/java/org/springframework/web/reactive/FlushingIntegrationTests.java +++ b/spring-web-reactive/src/test/java/org/springframework/web/reactive/FlushingIntegrationTests.java @@ -45,12 +45,14 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest private WebClient webClient; + @Before public void setup() throws Exception { super.setup(); this.webClient = WebClient.create(new ReactorClientHttpConnector()); } + @Test public void writeAndFlushWith() throws Exception { ClientRequest request = ClientRequest.GET("http://localhost:" + port + "/write-and-flush").build(); @@ -93,11 +95,13 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest .verify(Duration.ofSeconds(10L)); } + @Override protected HttpHandler createHttpHandler() { return new FlushingHandler(); } + private static class FlushingHandler implements HttpHandler { @Override @@ -136,7 +140,6 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest buffer.write(data); return buffer; } - } } diff --git a/src/test/java/org/springframework/aop/config/AopNamespaceHandlerScopeIntegrationTests.java b/src/test/java/org/springframework/aop/config/AopNamespaceHandlerScopeIntegrationTests.java index 8bb127473f7..41f6524863c 100644 --- a/src/test/java/org/springframework/aop/config/AopNamespaceHandlerScopeIntegrationTests.java +++ b/src/test/java/org/springframework/aop/config/AopNamespaceHandlerScopeIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2016 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. @@ -16,14 +16,9 @@ package org.springframework.aop.config; -import static java.lang.String.format; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; - import org.junit.Before; import org.junit.Test; + import org.springframework.aop.framework.Advised; import org.springframework.aop.support.AopUtils; import org.springframework.context.ApplicationContext; @@ -37,31 +32,35 @@ import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.context.support.XmlWebApplicationContext; +import static java.lang.String.format; +import static org.junit.Assert.*; + /** * Integration tests for scoped proxy use in conjunction with aop: namespace. * Deemed an integration test because .web mocks and application contexts are required. * - * @see org.springframework.aop.config.AopNamespaceHandlerTests - * * @author Rob Harrop * @author Juergen Hoeller * @author Chris Beams + * @see org.springframework.aop.config.AopNamespaceHandlerTests */ public class AopNamespaceHandlerScopeIntegrationTests { - private static final String CLASSNAME = AopNamespaceHandlerScopeIntegrationTests.class.getName(); - private static final String CONTEXT = format("classpath:%s-context.xml", ClassUtils.convertClassNameToResourcePath(CLASSNAME)); + private static final String CONTEXT = format("classpath:%s-context.xml", + ClassUtils.convertClassNameToResourcePath(AopNamespaceHandlerScopeIntegrationTests.class.getName())); private ApplicationContext context; + @Before public void setUp() { XmlWebApplicationContext wac = new XmlWebApplicationContext(); - wac.setConfigLocations(new String[] {CONTEXT}); + wac.setConfigLocations(CONTEXT); wac.refresh(); this.context = wac; } + @Test public void testSingletonScoping() throws Exception { ITestBean scoped = (ITestBean) this.context.getBean("singletonScoped");