Skip to content

Commit e210f08

Browse files
committed
Declare Advisor#isPerInstance() as default method
Includes INSTANCE constants on default factory classes. Closes gh-30614
1 parent 2317bef commit e210f08

10 files changed

+33
-56
lines changed

spring-aop/src/main/java/org/springframework/aop/Advisor.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -62,8 +62,11 @@ public interface Advisor {
6262
* Typical Advisor implementations always return {@code true}.
6363
* Use singleton/prototype bean definitions or appropriate programmatic
6464
* proxy creation to ensure that Advisors have the correct lifecycle model.
65+
* <p>As of 6.0.10, the default implementation returns {@code true}.
6566
* @return whether this advice is associated with a particular target instance
6667
*/
67-
boolean isPerInstance();
68+
default boolean isPerInstance() {
69+
return true;
70+
}
6871

6972
}

spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -67,11 +67,6 @@ public int getOrder() {
6767
}
6868
}
6969

70-
@Override
71-
public boolean isPerInstance() {
72-
return true;
73-
}
74-
7570
@Override
7671
public Advice getAdvice() {
7772
return this.advice;

spring-aop/src/main/java/org/springframework/aop/aspectj/DeclareParentsAdvisor.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -91,11 +91,6 @@ public void validateInterfaces() throws IllegalArgumentException {
9191
// Do nothing
9292
}
9393

94-
@Override
95-
public boolean isPerInstance() {
96-
return true;
97-
}
98-
9994
@Override
10095
public Advice getAdvice() {
10196
return this.advice;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747
@SuppressWarnings("serial")
4848
public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializable {
4949

50+
/**
51+
* Singleton instance of this class.
52+
* @since 6.0.10
53+
*/
54+
public static final DefaultAdvisorChainFactory INSTANCE = new DefaultAdvisorChainFactory();
55+
56+
5057
@Override
5158
public List<Object> getInterceptorsAndDynamicInterceptionAdvice(
5259
Advised config, Method method, @Nullable Class<?> targetClass) {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -48,6 +48,12 @@
4848
*/
4949
public class DefaultAopProxyFactory implements AopProxyFactory, Serializable {
5050

51+
/**
52+
* Singleton instance of this class.
53+
* @since 6.0.10
54+
*/
55+
public static final DefaultAopProxyFactory INSTANCE = new DefaultAopProxyFactory();
56+
5157
private static final long serialVersionUID = 7930414337282325166L;
5258

5359

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -44,7 +44,7 @@ public class ProxyCreatorSupport extends AdvisedSupport {
4444
* Create a new ProxyCreatorSupport instance.
4545
*/
4646
public ProxyCreatorSupport() {
47-
this.aopProxyFactory = new DefaultAopProxyFactory();
47+
this.aopProxyFactory = DefaultAopProxyFactory.INSTANCE;
4848
}
4949

5050
/**

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -606,11 +606,6 @@ public Advice getAdvice() {
606606
throw new UnsupportedOperationException("Cannot invoke methods: " + this.message);
607607
}
608608

609-
@Override
610-
public boolean isPerInstance() {
611-
throw new UnsupportedOperationException("Cannot invoke methods: " + this.message);
612-
}
613-
614609
@Override
615610
public String toString() {
616611
return this.message;

spring-aop/src/main/java/org/springframework/aop/support/AbstractPointcutAdvisor.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -58,22 +58,12 @@ public int getOrder() {
5858
return Ordered.LOWEST_PRECEDENCE;
5959
}
6060

61-
@Override
62-
public boolean isPerInstance() {
63-
return true;
64-
}
65-
6661

6762
@Override
6863
public boolean equals(@Nullable Object other) {
69-
if (this == other) {
70-
return true;
71-
}
72-
if (!(other instanceof PointcutAdvisor otherAdvisor)) {
73-
return false;
74-
}
75-
return (ObjectUtils.nullSafeEquals(getAdvice(), otherAdvisor.getAdvice()) &&
76-
ObjectUtils.nullSafeEquals(getPointcut(), otherAdvisor.getPointcut()));
64+
return (this == other || (other instanceof PointcutAdvisor otherAdvisor &&
65+
ObjectUtils.nullSafeEquals(getAdvice(), otherAdvisor.getAdvice()) &&
66+
ObjectUtils.nullSafeEquals(getPointcut(), otherAdvisor.getPointcut())));
7767
}
7868

7969
@Override

spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -134,11 +134,6 @@ public Advice getAdvice() {
134134
return this.advice;
135135
}
136136

137-
@Override
138-
public boolean isPerInstance() {
139-
return true;
140-
}
141-
142137
@Override
143138
public ClassFilter getClassFilter() {
144139
return this;
@@ -152,13 +147,9 @@ public boolean matches(Class<?> clazz) {
152147

153148
@Override
154149
public boolean equals(@Nullable Object other) {
155-
if (this == other) {
156-
return true;
157-
}
158-
if (!(other instanceof DefaultIntroductionAdvisor otherAdvisor)) {
159-
return false;
160-
}
161-
return (this.advice.equals(otherAdvisor.advice) && this.interfaces.equals(otherAdvisor.interfaces));
150+
return (this == other || (other instanceof DefaultIntroductionAdvisor otherAdvisor &&
151+
this.advice.equals(otherAdvisor.advice) &&
152+
this.interfaces.equals(otherAdvisor.interfaces)));
162153
}
163154

164155
@Override

spring-aop/src/main/java/org/springframework/aop/support/StaticMethodMatcherPointcutAdvisor.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -77,11 +77,6 @@ public Advice getAdvice() {
7777
return this.advice;
7878
}
7979

80-
@Override
81-
public boolean isPerInstance() {
82-
return true;
83-
}
84-
8580
@Override
8681
public Pointcut getPointcut() {
8782
return this;

0 commit comments

Comments
 (0)