Support annotations on interfaces in AnnotatedElementUtils

This commit introduces support in AnnotatedElementUtils for finding
annotations declared on interfaces at the type level.

NB: this commit does not include support for finding annotations
declared on interface methods.

In order to maintain backward compatibility with @Transactional
annotation attribute processing, a new getAnnotationAttributes() method
has been added to AnnotatedElementUtils that provides a flag to control
whether interfaces should be searched.
SpringTransactionAnnotationParser and JtaTransactionAnnotationParser
have been updated accordingly to ensure that interfaces are not
unintentionally searched in the @Transactional resolution process.

This commit also introduces additional tests and updates TODOs for
SPR-12738.

Issue: SPR-12944, SPR-12738
This commit is contained in:
Sam Brannen
2015-04-22 21:32:06 +02:00
parent 9b7fd8be4d
commit 7f0f04dfe3
5 changed files with 210 additions and 47 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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.
@@ -32,6 +32,7 @@ import org.springframework.transaction.interceptor.TransactionAttribute;
* Strategy implementation for parsing JTA 1.2's {@link javax.transaction.Transactional} annotation.
*
* @author Juergen Hoeller
* @author Sam Brannen
* @since 4.0
*/
@SuppressWarnings("serial")
@@ -39,7 +40,8 @@ public class JtaTransactionAnnotationParser implements TransactionAnnotationPars
@Override
public TransactionAttribute parseTransactionAnnotation(AnnotatedElement ae) {
AnnotationAttributes ann = AnnotatedElementUtils.getAnnotationAttributes(ae, javax.transaction.Transactional.class.getName());
AnnotationAttributes ann = AnnotatedElementUtils.getAnnotationAttributes(ae,
javax.transaction.Transactional.class.getName(), false, false, false, false);
if (ann != null) {
return parseTransactionAnnotation(ann);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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.
@@ -32,6 +32,7 @@ import org.springframework.transaction.interceptor.TransactionAttribute;
* Strategy implementation for parsing Spring's {@link Transactional} annotation.
*
* @author Juergen Hoeller
* @author Sam Brannen
* @since 2.5
*/
@SuppressWarnings("serial")
@@ -39,7 +40,8 @@ public class SpringTransactionAnnotationParser implements TransactionAnnotationP
@Override
public TransactionAttribute parseTransactionAnnotation(AnnotatedElement ae) {
AnnotationAttributes ann = AnnotatedElementUtils.getAnnotationAttributes(ae, Transactional.class.getName());
AnnotationAttributes ann = AnnotatedElementUtils.getAnnotationAttributes(ae, Transactional.class.getName(),
false, false, false, false);
if (ann != null) {
return parseTransactionAnnotation(ann);
}