diff --git a/spring-aop/src/main/java/org/springframework/aop/Advisor.java b/spring-aop/src/main/java/org/springframework/aop/Advisor.java index b10911aebf2a..100fbd07797e 100644 --- a/spring-aop/src/main/java/org/springframework/aop/Advisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/Advisor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -62,8 +62,11 @@ public interface Advisor { * Typical Advisor implementations always return {@code true}. * Use singleton/prototype bean definitions or appropriate programmatic * proxy creation to ensure that Advisors have the correct lifecycle model. + *

As of 6.0.10, the default implementation returns {@code true}. * @return whether this advice is associated with a particular target instance */ - boolean isPerInstance(); + default boolean isPerInstance() { + return true; + } } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java index 605a55e327d2..44200eadb2b2 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java @@ -67,11 +67,6 @@ public int getOrder() { } } - @Override - public boolean isPerInstance() { - return true; - } - @Override public Advice getAdvice() { return this.advice; diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/DeclareParentsAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/DeclareParentsAdvisor.java index 3a4f8992cb14..43233666adf3 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/DeclareParentsAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/DeclareParentsAdvisor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -91,11 +91,6 @@ public void validateInterfaces() throws IllegalArgumentException { // Do nothing } - @Override - public boolean isPerInstance() { - return true; - } - @Override public Advice getAdvice() { return this.advice; diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java b/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java index 5bef4c501c84..73c2fb430896 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java @@ -47,6 +47,13 @@ @SuppressWarnings("serial") public class DefaultAdvisorChainFactory implements AdvisorChainFactory, Serializable { + /** + * Singleton instance of this class. + * @since 6.0.10 + */ + public static final DefaultAdvisorChainFactory INSTANCE = new DefaultAdvisorChainFactory(); + + @Override public List getInterceptorsAndDynamicInterceptionAdvice( Advised config, Method method, @Nullable Class targetClass) { diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAopProxyFactory.java b/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAopProxyFactory.java index 5710f8e03bc3..f97455dfc45c 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAopProxyFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAopProxyFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,6 +48,12 @@ */ public class DefaultAopProxyFactory implements AopProxyFactory, Serializable { + /** + * Singleton instance of this class. + * @since 6.0.10 + */ + public static final DefaultAopProxyFactory INSTANCE = new DefaultAopProxyFactory(); + private static final long serialVersionUID = 7930414337282325166L; diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.java b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.java index 096294321f80..a9b43befbc9b 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyCreatorSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ public class ProxyCreatorSupport extends AdvisedSupport { * Create a new ProxyCreatorSupport instance. */ public ProxyCreatorSupport() { - this.aopProxyFactory = new DefaultAopProxyFactory(); + this.aopProxyFactory = DefaultAopProxyFactory.INSTANCE; } /** diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java index 77b8858171f7..f963721c58b2 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -606,11 +606,6 @@ public Advice getAdvice() { throw new UnsupportedOperationException("Cannot invoke methods: " + this.message); } - @Override - public boolean isPerInstance() { - throw new UnsupportedOperationException("Cannot invoke methods: " + this.message); - } - @Override public String toString() { return this.message; diff --git a/spring-aop/src/main/java/org/springframework/aop/support/AbstractPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/AbstractPointcutAdvisor.java index 6937e31ce273..fc5527270ed8 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/AbstractPointcutAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/AbstractPointcutAdvisor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -58,22 +58,12 @@ public int getOrder() { return Ordered.LOWEST_PRECEDENCE; } - @Override - public boolean isPerInstance() { - return true; - } - @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof PointcutAdvisor otherAdvisor)) { - return false; - } - return (ObjectUtils.nullSafeEquals(getAdvice(), otherAdvisor.getAdvice()) && - ObjectUtils.nullSafeEquals(getPointcut(), otherAdvisor.getPointcut())); + return (this == other || (other instanceof PointcutAdvisor otherAdvisor && + ObjectUtils.nullSafeEquals(getAdvice(), otherAdvisor.getAdvice()) && + ObjectUtils.nullSafeEquals(getPointcut(), otherAdvisor.getPointcut()))); } @Override diff --git a/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java index 8b70d019fe8f..930255c62cd6 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -134,11 +134,6 @@ public Advice getAdvice() { return this.advice; } - @Override - public boolean isPerInstance() { - return true; - } - @Override public ClassFilter getClassFilter() { return this; @@ -152,13 +147,9 @@ public boolean matches(Class clazz) { @Override public boolean equals(@Nullable Object other) { - if (this == other) { - return true; - } - if (!(other instanceof DefaultIntroductionAdvisor otherAdvisor)) { - return false; - } - return (this.advice.equals(otherAdvisor.advice) && this.interfaces.equals(otherAdvisor.interfaces)); + return (this == other || (other instanceof DefaultIntroductionAdvisor otherAdvisor && + this.advice.equals(otherAdvisor.advice) && + this.interfaces.equals(otherAdvisor.interfaces))); } @Override diff --git a/spring-aop/src/main/java/org/springframework/aop/support/StaticMethodMatcherPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/StaticMethodMatcherPointcutAdvisor.java index 38dceb30086b..f5b3ccdeaa79 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/StaticMethodMatcherPointcutAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/StaticMethodMatcherPointcutAdvisor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -77,11 +77,6 @@ public Advice getAdvice() { return this.advice; } - @Override - public boolean isPerInstance() { - return true; - } - @Override public Pointcut getPointcut() { return this;