Browse Source

Narrow Aware interface exclusion check to BeanFactoryAware only

Closes gh-35835

(cherry picked from commit de5b9aab55)
pull/35859/head
Juergen Hoeller 4 weeks ago
parent
commit
f94645de17
  1. 6
      spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractFallbackJCacheOperationSource.java
  2. 6
      spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java
  3. 6
      spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java
  4. 28
      spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSourceTests.java

6
spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractFallbackJCacheOperationSource.java vendored

@ -25,7 +25,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.Aware; import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.core.MethodClassKey; import org.springframework.core.MethodClassKey;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
@ -98,8 +98,8 @@ public abstract class AbstractFallbackJCacheOperationSource implements JCacheOpe
if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) { if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) {
return null; return null;
} }
// Skip methods declared on BeanFactoryAware and co. // Skip setBeanFactory method on BeanFactoryAware.
if (method.getDeclaringClass().isInterface() && Aware.class.isAssignableFrom(method.getDeclaringClass())) { if (method.getDeclaringClass() == BeanFactoryAware.class) {
return null; return null;
} }

6
spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java vendored

@ -27,7 +27,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.Aware; import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.core.MethodClassKey; import org.springframework.core.MethodClassKey;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
@ -140,8 +140,8 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) { if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) {
return null; return null;
} }
// Skip methods declared on BeanFactoryAware and co. // Skip setBeanFactory method on BeanFactoryAware.
if (method.getDeclaringClass().isInterface() && Aware.class.isAssignableFrom(method.getDeclaringClass())) { if (method.getDeclaringClass() == BeanFactoryAware.class) {
return null; return null;
} }

6
spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java

@ -25,7 +25,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.Aware; import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.context.EmbeddedValueResolverAware; import org.springframework.context.EmbeddedValueResolverAware;
import org.springframework.core.MethodClassKey; import org.springframework.core.MethodClassKey;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
@ -167,8 +167,8 @@ public abstract class AbstractFallbackTransactionAttributeSource
if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) { if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) {
return null; return null;
} }
// Skip methods declared on BeanFactoryAware and co. // Skip setBeanFactory method on BeanFactoryAware.
if (method.getDeclaringClass().isInterface() && Aware.class.isAssignableFrom(method.getDeclaringClass())) { if (method.getDeclaringClass() == BeanFactoryAware.class) {
return null; return null;
} }

28
spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSourceTests.java

@ -32,6 +32,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.Advised;
import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.framework.ProxyFactory;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.core.annotation.AliasFor; import org.springframework.core.annotation.AliasFor;
import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.testfixture.io.SerializationTestUtils; import org.springframework.core.testfixture.io.SerializationTestUtils;
@ -59,6 +60,7 @@ class AnnotationTransactionAttributeSourceTests {
private final AnnotationTransactionAttributeSource attributeSource = new AnnotationTransactionAttributeSource(); private final AnnotationTransactionAttributeSource attributeSource = new AnnotationTransactionAttributeSource();
@Test @Test
void serializable() throws Exception { void serializable() throws Exception {
TestBean1 tb = new TestBean1(); TestBean1 tb = new TestBean1();
@ -123,6 +125,10 @@ class AnnotationTransactionAttributeSourceTests {
void transactionAttributeDeclaredOnInterfaceMethodOnly() { void transactionAttributeDeclaredOnInterfaceMethodOnly() {
TransactionAttribute actual = getTransactionAttribute(TestBean2.class, ITestBean2.class, "getAge"); TransactionAttribute actual = getTransactionAttribute(TestBean2.class, ITestBean2.class, "getAge");
assertThat(actual).satisfies(hasNoRollbackRule()); assertThat(actual).satisfies(hasNoRollbackRule());
actual = getTransactionAttribute(TestBean2.class, ITestBean2X.class, "getAge");
assertThat(actual).satisfies(hasNoRollbackRule());
actual = getTransactionAttribute(ITestBean2X.class, ITestBean2X.class, "getAge");
assertThat(actual).satisfies(hasNoRollbackRule());
} }
/** /**
@ -249,6 +255,7 @@ class AnnotationTransactionAttributeSourceTests {
assertThat(actual.isReadOnly()).isTrue(); assertThat(actual.isReadOnly()).isTrue();
} }
@Nested @Nested
class JtaAttributeTests { class JtaAttributeTests {
@ -276,6 +283,7 @@ class AnnotationTransactionAttributeSourceTests {
assertThat(getNameAttr.getPropagationBehavior()).isEqualTo(TransactionAttribute.PROPAGATION_SUPPORTS); assertThat(getNameAttr.getPropagationBehavior()).isEqualTo(TransactionAttribute.PROPAGATION_SUPPORTS);
} }
static class JtaAnnotatedBean1 implements ITestBean1 { static class JtaAnnotatedBean1 implements ITestBean1 {
private String name; private String name;
@ -305,7 +313,6 @@ class AnnotationTransactionAttributeSourceTests {
} }
} }
@jakarta.transaction.Transactional(jakarta.transaction.Transactional.TxType.SUPPORTS) @jakarta.transaction.Transactional(jakarta.transaction.Transactional.TxType.SUPPORTS)
static class JtaAnnotatedBean2 implements ITestBean1 { static class JtaAnnotatedBean2 implements ITestBean1 {
@ -362,7 +369,6 @@ class AnnotationTransactionAttributeSourceTests {
} }
} }
@jakarta.transaction.Transactional(jakarta.transaction.Transactional.TxType.SUPPORTS) @jakarta.transaction.Transactional(jakarta.transaction.Transactional.TxType.SUPPORTS)
interface ITestJta { interface ITestJta {
@ -375,9 +381,9 @@ class AnnotationTransactionAttributeSourceTests {
void setName(String name); void setName(String name);
} }
} }
@Nested @Nested
class Ejb3AttributeTests { class Ejb3AttributeTests {
@ -448,7 +454,6 @@ class AnnotationTransactionAttributeSourceTests {
} }
} }
@jakarta.ejb.TransactionAttribute(TransactionAttributeType.SUPPORTS) @jakarta.ejb.TransactionAttribute(TransactionAttributeType.SUPPORTS)
static class Ejb3AnnotatedBean2 implements ITestBean1 { static class Ejb3AnnotatedBean2 implements ITestBean1 {
@ -506,6 +511,7 @@ class AnnotationTransactionAttributeSourceTests {
} }
} }
@Nested @Nested
class GroovyTests { class GroovyTests {
@ -519,6 +525,7 @@ class AnnotationTransactionAttributeSourceTests {
assertThat(attributeSource.getTransactionAttribute(getMetaClassMethod, GroovyTestBean.class)).isNull(); assertThat(attributeSource.getTransactionAttribute(getMetaClassMethod, GroovyTestBean.class)).isNull();
} }
@Transactional @Transactional
static class GroovyTestBean implements ITestBean1, GroovyObject { static class GroovyTestBean implements ITestBean1, GroovyObject {
@ -571,6 +578,7 @@ class AnnotationTransactionAttributeSourceTests {
} }
} }
private Consumer<TransactionAttribute> hasRollbackRules(RollbackRuleAttribute... rollbackRuleAttributes) { private Consumer<TransactionAttribute> hasRollbackRules(RollbackRuleAttribute... rollbackRuleAttributes) {
return transactionAttribute -> { return transactionAttribute -> {
RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute(); RuleBasedTransactionAttribute rbta = new RuleBasedTransactionAttribute();
@ -626,7 +634,12 @@ class AnnotationTransactionAttributeSourceTests {
} }
interface ITestBean2X extends ITestBean2 { interface ITestBean2X extends ITestBean2, BeanNameAware {
@Transactional
int getAge();
void setAge(int age);
String getName(); String getName();
@ -735,6 +748,10 @@ class AnnotationTransactionAttributeSourceTests {
this.age = age; this.age = age;
} }
@Override
public void setBeanName(String name) {
}
@Override @Override
public String getName() { public String getName() {
return name; return name;
@ -917,6 +934,7 @@ class AnnotationTransactionAttributeSourceTests {
} }
} }
@Transactional(label = {"retryable", "long-running"}) @Transactional(label = {"retryable", "long-running"})
static class TestBean11 { static class TestBean11 {

Loading…
Cancel
Save