Have HotSwappableTargetSource.swap() take effect immediately if called within an interceptor [SPR-1238] #5941
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: declined
A suggestion or change that we don't feel we should currently apply
type: enhancement
A general enhancement
Ryan Stone opened SPR-1238 and commented
In the following code, in a MethodInterceptor, the target of the of the proxy is swapped with a HotSwappableTargetSource. However, when you call MethodInvocation.proceed(), the old target is still used for the current invocation. In subsequent invocations, the new target will be used.
//This interceptor:
public class TestCaseInterceptor implements MethodInterceptor, BeanFactoryAware {
private BeanFactory beanFactory;
private int count = 0;
}
//the advised class:
public class ProxiedClass {
private static int nextInstanceId = 0;
}
<!-- The Spring configuration file: -->
<beans>
<bean id="proxy" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyTargetClass"><value>true</value></property>
<property name="singleton">
<value>false</value>
</property>
<property name="exposeProxy">
<value>true</value>
</property>
<property name="targetSource" ref="swapper"/>
<property name="interceptorNames">
<list>
<value>targetAdvisor</value>
</list>
</property>
</bean>
</beans>
//The testcase:
public class TestCase {
public static void main(String [] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("testcase-context.xml");
}
The output:
This is instance #0
This is instance #0
This is instance #0
This is instance #0
swapping...
This is instance #0
This is instance #2
This is instance #2
This is instance #2
This is instance #2
swapping...
This is instance #2
This is instance #3
This is instance #3
This is instance #3
This is instance #3
swapping...
This is instance #3
This is instance #4
This is instance #4
This is instance #4
This is instance #4
swapping...
This is instance #4
2 votes, 3 watchers
The text was updated successfully, but these errors were encountered: