Polishing
This commit is contained in:
parent
a5c6658d2c
commit
fc629bb508
|
@ -55,26 +55,25 @@ import org.springframework.util.StringUtils;
|
||||||
* before invoking the bean itself.
|
* before invoking the bean itself.
|
||||||
*
|
*
|
||||||
* <p>This class distinguishes between "common" interceptors: shared for all proxies it
|
* <p>This class distinguishes between "common" interceptors: shared for all proxies it
|
||||||
* creates, and "specific" interceptors: unique per bean instance. There need not
|
* creates, and "specific" interceptors: unique per bean instance. There need not be any
|
||||||
* be any common interceptors. If there are, they are set using the interceptorNames
|
* common interceptors. If there are, they are set using the interceptorNames property.
|
||||||
* property. As with ProxyFactoryBean, interceptors names in the current factory
|
* As with {@link org.springframework.aop.framework.ProxyFactoryBean}, interceptors names
|
||||||
* are used rather than bean references to allow correct handling of prototype
|
* in the current factory are used rather than bean references to allow correct handling
|
||||||
* advisors and interceptors: for example, to support stateful mixins.
|
* of prototype advisors and interceptors: for example, to support stateful mixins.
|
||||||
* Any advice type is supported for "interceptorNames" entries.
|
* Any advice type is supported for {@link #setInterceptorNames "interceptorNames"} entries.
|
||||||
*
|
*
|
||||||
* <p>Such auto-proxying is particularly useful if there's a large number of beans that
|
* <p>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.
|
* 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
|
* 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.
|
* one single such post processor with the bean factory to achieve the same effect.
|
||||||
*
|
*
|
||||||
* <p>Subclasses can apply any strategy to decide if a bean is to be proxied,
|
* <p>Subclasses can apply any strategy to decide if a bean is to be proxied, e.g. by type,
|
||||||
* e.g. by type, by name, by definition details, etc. They can also return
|
* by name, by definition details, etc. They can also return additional interceptors that
|
||||||
* additional interceptors that should just be applied to the specific bean
|
* should just be applied to the specific bean instance. A simple concrete implementation is
|
||||||
* instance. The default concrete implementation is BeanNameAutoProxyCreator,
|
* {@link BeanNameAutoProxyCreator}, identifying the beans to be proxied via given names.
|
||||||
* identifying the beans to be proxied via a list of bean names.
|
|
||||||
*
|
*
|
||||||
* <p>Any number of {@link TargetSourceCreator} implementations can be used to create
|
* <p>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
|
* 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,
|
* {@link org.springframework.aop.TargetSource}. If there are no TargetSourceCreators set,
|
||||||
* or if none matches, a {@link org.springframework.aop.target.SingletonTargetSource}
|
* 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 BeanFactory beanFactory;
|
||||||
|
|
||||||
private final Set<String> targetSourcedBeans =
|
private final Set<String> targetSourcedBeans = Collections.newSetFromMap(new ConcurrentHashMap<>(16));
|
||||||
Collections.newSetFromMap(new ConcurrentHashMap<>(16));
|
|
||||||
|
|
||||||
private final Set<Object> earlyProxyReferences =
|
private final Set<Object> earlyProxyReferences = Collections.newSetFromMap(new ConcurrentHashMap<>(16));
|
||||||
Collections.newSetFromMap(new ConcurrentHashMap<>(16));
|
|
||||||
|
|
||||||
private final Map<Object, Class<?>> proxyTypes = new ConcurrentHashMap<>(16);
|
private final Map<Object, Class<?>> proxyTypes = new ConcurrentHashMap<>(16);
|
||||||
|
|
||||||
|
@ -156,8 +153,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify the AdvisorAdapterRegistry to use.
|
* Specify the {@link AdvisorAdapterRegistry} to use.
|
||||||
* Default is the global AdvisorAdapterRegistry.
|
* <p>Default is the global {@link AdvisorAdapterRegistry}.
|
||||||
* @see org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry
|
* @see org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry
|
||||||
*/
|
*/
|
||||||
public void setAdvisorAdapterRegistry(AdvisorAdapterRegistry advisorAdapterRegistry) {
|
public void setAdvisorAdapterRegistry(AdvisorAdapterRegistry advisorAdapterRegistry) {
|
||||||
|
@ -165,18 +162,18 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set custom TargetSourceCreators to be applied in this order.
|
* Set custom {@code TargetSourceCreators} to be applied in this order.
|
||||||
* If the list is empty, or they all return null, a SingletonTargetSource
|
* If the list is empty, or they all return null, a {@link SingletonTargetSource}
|
||||||
* will be created for each bean.
|
* will be created for each bean.
|
||||||
* <p>Note that TargetSourceCreators will kick in even for target beans
|
* <p>Note that TargetSourceCreators will kick in even for target beans
|
||||||
* where no advices or advisors have been found. If a TargetSourceCreator
|
* where no advices or advisors have been found. If a {@code TargetSourceCreator}
|
||||||
* returns a TargetSource for a specific bean, that bean will be proxied
|
* returns a {@link TargetSource} for a specific bean, that bean will be proxied
|
||||||
* in any case.
|
* in any case.
|
||||||
* <p>TargetSourceCreators can only be invoked if this post processor is used
|
* <p>{@code TargetSourceCreators} can only be invoked if this post processor is used
|
||||||
* in a BeanFactory, and its BeanFactoryAware callback is used.
|
* in a {@link BeanFactory} and its {@link BeanFactoryAware} callback is triggered.
|
||||||
* @param targetSourceCreators list of TargetSourceCreator.
|
* @param targetSourceCreators the list of {@code TargetSourceCreators}.
|
||||||
* Ordering is significant: The TargetSource returned from the first matching
|
* Ordering is significant: The {@code TargetSource} returned from the first matching
|
||||||
* TargetSourceCreator (that is, the first that returns non-null) will be used.
|
* {@code TargetSourceCreator} (that is, the first that returns non-null) will be used.
|
||||||
*/
|
*/
|
||||||
public void setCustomTargetSourceCreators(TargetSourceCreator... targetSourceCreators) {
|
public void setCustomTargetSourceCreators(TargetSourceCreator... targetSourceCreators) {
|
||||||
this.customTargetSourceCreators = targetSourceCreators;
|
this.customTargetSourceCreators = targetSourceCreators;
|
||||||
|
@ -207,8 +204,8 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the owning BeanFactory.
|
* Return the owning {@link BeanFactory}.
|
||||||
* May be {@code null}, as this object doesn't need to belong to a bean factory.
|
* May be {@code null}, as this post-processor doesn't need to belong to a bean factory.
|
||||||
*/
|
*/
|
||||||
protected BeanFactory getBeanFactory() {
|
protected BeanFactory getBeanFactory() {
|
||||||
return this.beanFactory;
|
return this.beanFactory;
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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 <i>merged</i> bean definitions at runtime.
|
* Post-processor callback interface for <i>merged</i> bean definitions at runtime.
|
||||||
* {@link BeanPostProcessor} implementations may implement this sub-interface in
|
* {@link BeanPostProcessor} implementations may implement this sub-interface in order
|
||||||
* order to post-process the merged bean definition that the Spring BeanFactory
|
* to post-process the merged bean definition (a processed copy of the original bean
|
||||||
* uses to create a specific bean instance.
|
* definition) that the Spring {@code BeanFactory} uses to create a bean instance.
|
||||||
*
|
*
|
||||||
* <p>The {@link #postProcessMergedBeanDefinition} method may for example introspect
|
* <p>The {@link #postProcessMergedBeanDefinition} method may for example introspect
|
||||||
* the bean definition in order to prepare some cached metadata before post-processing
|
* 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
|
* actual instances of a bean. It is also allowed to modify the bean definition but
|
||||||
* but <i>only</i> for bean definition properties which are actually intended
|
* <i>only</i> for definition properties which are actually intended for concurrent
|
||||||
* for concurrent modification. Basically, this only applies to operations
|
* modification. Essentially, this only applies to operations defined on the
|
||||||
* defined on the {@link RootBeanDefinition} itself but not to the properties
|
* {@link RootBeanDefinition} itself but not to the properties of its base classes.
|
||||||
* of its base classes.
|
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
|
* @see org.springframework.beans.factory.config.ConfigurableBeanFactory#getMergedBeanDefinition
|
||||||
*/
|
*/
|
||||||
public interface MergedBeanDefinitionPostProcessor extends BeanPostProcessor {
|
public interface MergedBeanDefinitionPostProcessor extends BeanPostProcessor {
|
||||||
|
|
||||||
|
|
|
@ -437,11 +437,6 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
|
||||||
}
|
}
|
||||||
return bean;
|
return bean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object postProcessAfterInitialization(Object bean, String beanName) {
|
|
||||||
return bean;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,7 @@ import org.springframework.messaging.handler.annotation.support.MessageHandlerMe
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper bean for registering {@link JmsListenerEndpoint} with
|
* Helper bean for registering {@link JmsListenerEndpoint} with a {@link JmsListenerEndpointRegistry}.
|
||||||
* a {@link JmsListenerEndpointRegistry}.
|
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
@ -48,8 +47,7 @@ public class JmsListenerEndpointRegistrar implements BeanFactoryAware, Initializ
|
||||||
|
|
||||||
private BeanFactory beanFactory;
|
private BeanFactory beanFactory;
|
||||||
|
|
||||||
private final List<JmsListenerEndpointDescriptor> endpointDescriptors =
|
private final List<JmsListenerEndpointDescriptor> endpointDescriptors = new ArrayList<>();
|
||||||
new ArrayList<>();
|
|
||||||
|
|
||||||
private boolean startImmediately;
|
private boolean startImmediately;
|
||||||
|
|
||||||
|
|
|
@ -45,12 +45,14 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest
|
||||||
|
|
||||||
private WebClient webClient;
|
private WebClient webClient;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() throws Exception {
|
public void setup() throws Exception {
|
||||||
super.setup();
|
super.setup();
|
||||||
this.webClient = WebClient.create(new ReactorClientHttpConnector());
|
this.webClient = WebClient.create(new ReactorClientHttpConnector());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void writeAndFlushWith() throws Exception {
|
public void writeAndFlushWith() throws Exception {
|
||||||
ClientRequest<Void> request = ClientRequest.GET("http://localhost:" + port + "/write-and-flush").build();
|
ClientRequest<Void> request = ClientRequest.GET("http://localhost:" + port + "/write-and-flush").build();
|
||||||
|
@ -93,11 +95,13 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest
|
||||||
.verify(Duration.ofSeconds(10L));
|
.verify(Duration.ofSeconds(10L));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected HttpHandler createHttpHandler() {
|
protected HttpHandler createHttpHandler() {
|
||||||
return new FlushingHandler();
|
return new FlushingHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static class FlushingHandler implements HttpHandler {
|
private static class FlushingHandler implements HttpHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -136,7 +140,6 @@ public class FlushingIntegrationTests extends AbstractHttpHandlerIntegrationTest
|
||||||
buffer.write(data);
|
buffer.write(data);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,14 +16,9 @@
|
||||||
|
|
||||||
package org.springframework.aop.config;
|
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.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.aop.framework.Advised;
|
import org.springframework.aop.framework.Advised;
|
||||||
import org.springframework.aop.support.AopUtils;
|
import org.springframework.aop.support.AopUtils;
|
||||||
import org.springframework.context.ApplicationContext;
|
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.request.ServletRequestAttributes;
|
||||||
import org.springframework.web.context.support.XmlWebApplicationContext;
|
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.
|
* Integration tests for scoped proxy use in conjunction with aop: namespace.
|
||||||
* Deemed an integration test because .web mocks and application contexts are required.
|
* Deemed an integration test because .web mocks and application contexts are required.
|
||||||
*
|
*
|
||||||
* @see org.springframework.aop.config.AopNamespaceHandlerTests
|
|
||||||
*
|
|
||||||
* @author Rob Harrop
|
* @author Rob Harrop
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
|
* @see org.springframework.aop.config.AopNamespaceHandlerTests
|
||||||
*/
|
*/
|
||||||
public class AopNamespaceHandlerScopeIntegrationTests {
|
public class AopNamespaceHandlerScopeIntegrationTests {
|
||||||
|
|
||||||
private static final String CLASSNAME = AopNamespaceHandlerScopeIntegrationTests.class.getName();
|
private static final String CONTEXT = format("classpath:%s-context.xml",
|
||||||
private static final String CONTEXT = format("classpath:%s-context.xml", ClassUtils.convertClassNameToResourcePath(CLASSNAME));
|
ClassUtils.convertClassNameToResourcePath(AopNamespaceHandlerScopeIntegrationTests.class.getName()));
|
||||||
|
|
||||||
private ApplicationContext context;
|
private ApplicationContext context;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
XmlWebApplicationContext wac = new XmlWebApplicationContext();
|
XmlWebApplicationContext wac = new XmlWebApplicationContext();
|
||||||
wac.setConfigLocations(new String[] {CONTEXT});
|
wac.setConfigLocations(CONTEXT);
|
||||||
wac.refresh();
|
wac.refresh();
|
||||||
this.context = wac;
|
this.context = wac;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSingletonScoping() throws Exception {
|
public void testSingletonScoping() throws Exception {
|
||||||
ITestBean scoped = (ITestBean) this.context.getBean("singletonScoped");
|
ITestBean scoped = (ITestBean) this.context.getBean("singletonScoped");
|
||||||
|
|
Loading…
Reference in New Issue