Skip to content

Commit 43c1cec

Browse files
jhoellerunknown
authored andcommitted
Added "beforeExistingAdvisors" flag to AbstractAdvisingBeanPostProcessor
Just AsyncAnnotationBeanPostProcessor switches "beforeExistingAdvisors" to "true" by default. So effectively, MethodValidation/PersistenceExceptionTranslationPostProcessor apply after existing advisors by default again, fixing the 3.1->3.2 regression. Issue: SPR-10309
1 parent fffeaee commit 43c1cec

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

spring-aop/src/main/java/org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public abstract class AbstractAdvisingBeanPostProcessor extends ProxyConfig
3939

4040
protected Advisor advisor;
4141

42+
protected boolean beforeExistingAdvisors = false;
43+
4244
private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader();
4345

4446
/**
@@ -50,6 +52,19 @@ public abstract class AbstractAdvisingBeanPostProcessor extends ProxyConfig
5052
private final Map<Class, Boolean> eligibleBeans = new ConcurrentHashMap<Class, Boolean>(64);
5153

5254

55+
/**
56+
* Set whether this post-processor's advisor is supposed to apply before
57+
* existing advisors when encountering a pre-advised object.
58+
* <p>Default is "false", applying the advisor after existing advisors, i.e.
59+
* as close as possible to the target method. Switch this to "true" in order
60+
* for this post-processor's advisor to wrap existing advisors as well.
61+
* <p>Note: Check the concrete post-processor's javadoc whether it possibly
62+
* changes this flag by default, depending on the nature of its advisor.
63+
*/
64+
public void setBeforeExistingAdvisors(boolean beforeExistingAdvisors) {
65+
this.beforeExistingAdvisors = beforeExistingAdvisors;
66+
}
67+
5368
public void setBeanClassLoader(ClassLoader beanClassLoader) {
5469
this.beanClassLoader = beanClassLoader;
5570
}
@@ -74,7 +89,13 @@ public Object postProcessAfterInitialization(Object bean, String beanName) {
7489
}
7590
if (isEligible(bean, beanName)) {
7691
if (bean instanceof Advised) {
77-
((Advised) bean).addAdvisor(0, this.advisor);
92+
Advised advised = (Advised) bean;
93+
if (this.beforeExistingAdvisors) {
94+
advised.addAdvisor(0, this.advisor);
95+
}
96+
else {
97+
advised.addAdvisor(this.advisor);
98+
}
7899
return bean;
79100
}
80101
else {

spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationBeanPostProcessor.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -38,11 +38,15 @@
3838
* processor will detect both Spring's {@link Async @Async} annotation as well
3939
* as the EJB 3.1 {@code javax.ejb.Asynchronous} annotation.
4040
*
41+
* <p>Note: The underlying async advisor applies before existing advisors by default,
42+
* in order to switch to async execution as early as possible in the invocation chain.
43+
*
4144
* @author Mark Fisher
4245
* @author Juergen Hoeller
4346
* @since 3.0
4447
* @see Async
4548
* @see AsyncAnnotationAdvisor
49+
* @see #setBeforeExistingAdvisors
4650
*/
4751
@SuppressWarnings("serial")
4852
public class AsyncAnnotationBeanPostProcessor extends AbstractAdvisingBeanPostProcessor
@@ -53,6 +57,10 @@ public class AsyncAnnotationBeanPostProcessor extends AbstractAdvisingBeanPostPr
5357
private Executor executor;
5458

5559

60+
public AsyncAnnotationBeanPostProcessor() {
61+
setBeforeExistingAdvisors(true);
62+
}
63+
5664
/**
5765
* Set the 'async' annotation type to be detected at either class or method
5866
* level. By default, both the {@link Async} annotation and the EJB 3.1

0 commit comments

Comments
 (0)