Break out of loop once an AspectJ advice has been found

Closes gh-22449
This commit is contained in:
Juergen Hoeller
2019-02-25 17:24:02 +01:00
parent f07014ad37
commit cb54f201c2

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2018 the original author or authors. * Copyright 2002-2019 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.
@@ -27,27 +27,31 @@ import org.springframework.aop.interceptor.ExposeInvocationInterceptor;
* *
* @author Rod Johnson * @author Rod Johnson
* @author Ramnivas Laddad * @author Ramnivas Laddad
* @author Juergen Hoeller
* @since 2.0 * @since 2.0
*/ */
public abstract class AspectJProxyUtils { public abstract class AspectJProxyUtils {
/** /**
* Add special advisors if necessary to work with a proxy chain that contains AspectJ advisors. * Add special advisors if necessary to work with a proxy chain that contains AspectJ advisors:
* This will expose the current Spring AOP invocation (necessary for some AspectJ pointcut matching) * concretely, {@link ExposeInvocationInterceptor} at the beginning of the list.
* and make available the current AspectJ JoinPoint. The call will have no effect if there are no * <p>This will expose the current Spring AOP invocation (necessary for some AspectJ pointcut
* AspectJ advisors in the advisor chain. * matching) and make available the current AspectJ JoinPoint. The call will have no effect
* if there are no AspectJ advisors in the advisor chain.
* @param advisors the advisors available * @param advisors the advisors available
* @return {@code true} if any special {@link Advisor Advisors} were added, otherwise {@code false} * @return {@code true} if an {@link ExposeInvocationInterceptor} was added to the list,
* otherwise {@code false}
*/ */
public static boolean makeAdvisorChainAspectJCapableIfNecessary(List<Advisor> advisors) { public static boolean makeAdvisorChainAspectJCapableIfNecessary(List<Advisor> advisors) {
// Don't add advisors to an empty list; may indicate that proxying is just not required // Don't add advisors to an empty list; may indicate that proxying is just not required
if (!advisors.isEmpty()) { if (!advisors.isEmpty()) {
boolean foundAspectJAdvice = false; boolean foundAspectJAdvice = false;
for (Advisor advisor : advisors) { for (Advisor advisor : advisors) {
// Be careful not to get the Advice without a guard, as // Be careful not to get the Advice without a guard, as this might eagerly
// this might eagerly instantiate a non-singleton AspectJ aspect // instantiate a non-singleton AspectJ aspect...
if (isAspectJAdvice(advisor)) { if (isAspectJAdvice(advisor)) {
foundAspectJAdvice = true; foundAspectJAdvice = true;
break;
} }
} }
if (foundAspectJAdvice && !advisors.contains(ExposeInvocationInterceptor.ADVISOR)) { if (foundAspectJAdvice && !advisors.contains(ExposeInvocationInterceptor.ADVISOR)) {