diff --git a/spring-aop/src/main/java/org/springframework/aop/TargetSource.java b/spring-aop/src/main/java/org/springframework/aop/TargetSource.java index e894c5cb0a..c19982f319 100644 --- a/spring-aop/src/main/java/org/springframework/aop/TargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/TargetSource.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. @@ -49,10 +49,13 @@ public interface TargetSource extends TargetClassAware { * Will all calls to {@link #getTarget()} return the same object? *
In that case, there will be no need to invoke {@link #releaseTarget(Object)}, * and the AOP framework can cache the return value of {@link #getTarget()}. + *
The default implementation returns {@code false}. * @return {@code true} if the target is immutable * @see #getTarget */ - boolean isStatic(); + default boolean isStatic() { + return false; + } /** * Return a target instance. Invoked immediately before the @@ -67,9 +70,11 @@ public interface TargetSource extends TargetClassAware { /** * Release the given target object obtained from the * {@link #getTarget()} method, if any. + *
The default implementation is empty.
* @param target object obtained from a call to {@link #getTarget()}
* @throws Exception if the object can't be released
*/
- void releaseTarget(Object target) throws Exception;
+ default void releaseTarget(Object target) throws Exception {
+ }
}
diff --git a/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java
index 5bb7929b2d..6ab195c0a7 100644
--- a/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java
+++ b/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java
@@ -153,16 +153,6 @@ public abstract class AbstractBeanFactoryBasedTargetSource implements TargetSour
}
}
- @Override
- public boolean isStatic() {
- return false;
- }
-
- @Override
- public void releaseTarget(Object target) throws Exception {
- // Nothing to do here.
- }
-
/**
* Copy configuration from the other AbstractBeanFactoryBasedTargetSource object.
diff --git a/spring-aop/src/main/java/org/springframework/aop/target/AbstractLazyCreationTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/AbstractLazyCreationTargetSource.java
index 8246e1e626..5783875701 100644
--- a/spring-aop/src/main/java/org/springframework/aop/target/AbstractLazyCreationTargetSource.java
+++ b/spring-aop/src/main/java/org/springframework/aop/target/AbstractLazyCreationTargetSource.java
@@ -72,11 +72,6 @@ public abstract class AbstractLazyCreationTargetSource implements TargetSource {
return (this.lazyTarget != null ? this.lazyTarget.getClass() : null);
}
- @Override
- public boolean isStatic() {
- return false;
- }
-
/**
* Returns the lazy-initialized target object,
* creating it on-the-fly if it doesn't exist already.
@@ -91,11 +86,6 @@ public abstract class AbstractLazyCreationTargetSource implements TargetSource {
return this.lazyTarget;
}
- @Override
- public void releaseTarget(Object target) throws Exception {
- // nothing to do
- }
-
/**
* Subclasses should implement this method to return the lazy initialized object.
diff --git a/spring-aop/src/main/java/org/springframework/aop/target/EmptyTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/EmptyTargetSource.java
index 6b0fdfd498..cfcb3b119f 100644
--- a/spring-aop/src/main/java/org/springframework/aop/target/EmptyTargetSource.java
+++ b/spring-aop/src/main/java/org/springframework/aop/target/EmptyTargetSource.java
@@ -116,13 +116,6 @@ public final class EmptyTargetSource implements TargetSource, Serializable {
return null;
}
- /**
- * Nothing to release.
- */
- @Override
- public void releaseTarget(Object target) {
- }
-
/**
* Returns the canonical instance on deserialization in case
diff --git a/spring-aop/src/main/java/org/springframework/aop/target/HotSwappableTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/HotSwappableTargetSource.java
index 1a1a2fa755..fb5aceefca 100644
--- a/spring-aop/src/main/java/org/springframework/aop/target/HotSwappableTargetSource.java
+++ b/spring-aop/src/main/java/org/springframework/aop/target/HotSwappableTargetSource.java
@@ -66,21 +66,11 @@ public class HotSwappableTargetSource implements TargetSource, Serializable {
return this.target.getClass();
}
- @Override
- public final boolean isStatic() {
- return false;
- }
-
@Override
public synchronized Object getTarget() {
return this.target;
}
- @Override
- public void releaseTarget(Object target) {
- // nothing to do
- }
-
/**
* Swap the target, returning the old target object.
diff --git a/spring-aop/src/main/java/org/springframework/aop/target/SingletonTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/SingletonTargetSource.java
index e1b2ae6a56..11e3a9e8fe 100644
--- a/spring-aop/src/main/java/org/springframework/aop/target/SingletonTargetSource.java
+++ b/spring-aop/src/main/java/org/springframework/aop/target/SingletonTargetSource.java
@@ -67,11 +67,6 @@ public class SingletonTargetSource implements TargetSource, Serializable {
return this.target;
}
- @Override
- public void releaseTarget(Object target) {
- // nothing to do
- }
-
@Override
public boolean isStatic() {
return true;
diff --git a/spring-aop/src/main/java/org/springframework/aop/target/dynamic/AbstractRefreshableTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/dynamic/AbstractRefreshableTargetSource.java
index 32c6ce1c92..e6f386bf55 100644
--- a/spring-aop/src/main/java/org/springframework/aop/target/dynamic/AbstractRefreshableTargetSource.java
+++ b/spring-aop/src/main/java/org/springframework/aop/target/dynamic/AbstractRefreshableTargetSource.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.
@@ -73,14 +73,6 @@ public abstract class AbstractRefreshableTargetSource implements TargetSource, R
return this.targetObject.getClass();
}
- /**
- * Not static.
- */
- @Override
- public boolean isStatic() {
- return false;
- }
-
@Override
@Nullable
public final synchronized Object getTarget() {
@@ -90,13 +82,6 @@ public abstract class AbstractRefreshableTargetSource implements TargetSource, R
return this.targetObject;
}
- /**
- * No need to release target.
- */
- @Override
- public void releaseTarget(Object object) {
- }
-
@Override
public final synchronized void refresh() {
diff --git a/spring-aop/src/test/java/org/springframework/aop/target/PrototypeBasedTargetSourceTests.java b/spring-aop/src/test/java/org/springframework/aop/target/PrototypeBasedTargetSourceTests.java
index 6e857ffe6b..9d664ccc18 100644
--- a/spring-aop/src/test/java/org/springframework/aop/target/PrototypeBasedTargetSourceTests.java
+++ b/spring-aop/src/test/java/org/springframework/aop/target/PrototypeBasedTargetSourceTests.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.
@@ -75,14 +75,9 @@ public class PrototypeBasedTargetSourceTests {
private TestBean thisFieldIsNotSerializable = new TestBean();
@Override
- public Object getTarget() throws Exception {
+ public Object getTarget() {
return newPrototypeInstance();
}
-
- @Override
- public void releaseTarget(Object target) throws Exception {
- // Do nothing
- }
}
}
diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ContextAnnotationAutowireCandidateResolver.java b/spring-context/src/main/java/org/springframework/context/annotation/ContextAnnotationAutowireCandidateResolver.java
index f50fdff6a1..1718ffd4de 100644
--- a/spring-context/src/main/java/org/springframework/context/annotation/ContextAnnotationAutowireCandidateResolver.java
+++ b/spring-context/src/main/java/org/springframework/context/annotation/ContextAnnotationAutowireCandidateResolver.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.
@@ -85,7 +85,7 @@ public class ContextAnnotationAutowireCandidateResolver extends QualifierAnnotat
}
private Object buildLazyResolutionProxy(
- final DependencyDescriptor descriptor, final @Nullable String beanName, boolean classOnly) {
+ final DependencyDescriptor descriptor, @Nullable final String beanName, boolean classOnly) {
BeanFactory beanFactory = getBeanFactory();
Assert.state(beanFactory instanceof DefaultListableBeanFactory,
@@ -98,10 +98,6 @@ public class ContextAnnotationAutowireCandidateResolver extends QualifierAnnotat
return descriptor.getDependencyType();
}
@Override
- public boolean isStatic() {
- return false;
- }
- @Override
public Object getTarget() {
Set