diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/CacheAnnotationParser.java b/spring-context/src/main/java/org/springframework/cache/annotation/CacheAnnotationParser.java index 86351375ce9..e03bedee72f 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/CacheAnnotationParser.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/CacheAnnotationParser.java @@ -24,41 +24,40 @@ import org.springframework.lang.Nullable; /** * Strategy interface for parsing known caching annotation types. - * {@link AnnotationCacheOperationSource} delegates to such - * parsers for supporting specific annotation types such as Spring's own - * {@link Cacheable}, {@link CachePut} or {@link CacheEvict}. + * {@link AnnotationCacheOperationSource} delegates to such parsers + * for supporting specific annotation types such as Spring's own + * {@link Cacheable}, {@link CachePut} and{@link CacheEvict}. * * @author Costin Leau * @author Stephane Nicoll * @since 3.1 + * @see AnnotationCacheOperationSource + * @see SpringCacheAnnotationParser */ public interface CacheAnnotationParser { /** - * Parses the cache definition for the given class, - * based on a known annotation type. - *

This essentially parses a known cache annotation into Spring's - * metadata attribute class. Returns {@code null} if the class - * is not cacheable. + * Parse the cache definition for the given class, + * based on an annotation type understood by this parser. + *

This essentially parses a known cache annotation into Spring's metadata + * attribute class. Returns {@code null} if the class is not cacheable. * @param type the annotated class - * @return the configured caching operation, - * or {@code null} if none was found + * @return the configured caching operation, or {@code null} if none found * @see AnnotationCacheOperationSource#findCacheOperations(Class) */ @Nullable Collection parseCacheAnnotations(Class type); /** - * Parses the cache definition for the given method, - * based on a known annotation type. - *

This essentially parses a known cache annotation into Spring's - * metadata attribute class. Returns {@code null} if the method - * is not cacheable. + * Parse the cache definition for the given method, + * based on an annotation type understood by this parser. + *

This essentially parses a known cache annotation into Spring's metadata + * attribute class. Returns {@code null} if the method is not cacheable. * @param method the annotated method - * @return the configured caching operation, - * or {@code null} if none was found + * @return the configured caching operation, or {@code null} if none found * @see AnnotationCacheOperationSource#findCacheOperations(Method) */ @Nullable Collection parseCacheAnnotations(Method method); + } diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java b/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java index 4b5cb59614c..3991969b3d8 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java @@ -163,24 +163,22 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera /** - * Subclasses need to implement this to return the caching attribute - * for the given method, if any. - * @param method the method to retrieve the attribute for - * @return all caching attribute associated with this method - * (or {@code null} if none) + * Subclasses need to implement this to return the caching attribute for the + * given class, if any. + * @param clazz the class to retrieve the attribute for + * @return all caching attribute associated with this class, or {@code null} if none */ @Nullable - protected abstract Collection findCacheOperations(Method method); + protected abstract Collection findCacheOperations(Class clazz); /** - * Subclasses need to implement this to return the caching attribute - * for the given class, if any. - * @param clazz the class to retrieve the attribute for - * @return all caching attribute associated with this class - * (or {@code null} if none) + * Subclasses need to implement this to return the caching attribute for the + * given method, if any. + * @param method the method to retrieve the attribute for + * @return all caching attribute associated with this method, or {@code null} if none */ @Nullable - protected abstract Collection findCacheOperations(Class clazz); + protected abstract Collection findCacheOperations(Method method); /** * Should only public methods be allowed to have caching semantics? diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java index ea0bbf9d96b..6012cf9395e 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java @@ -99,7 +99,6 @@ public class EnableAsyncTests { fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { - ex.printStackTrace(); assertTrue(ex.getCause() instanceof BeanNotOfRequiredTypeException); } } @@ -114,7 +113,6 @@ public class EnableAsyncTests { fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { - ex.printStackTrace(); assertTrue(ex.getCause() instanceof BeanNotOfRequiredTypeException); } } @@ -244,8 +242,8 @@ public class EnableAsyncTests { ctx.close(); } - @Test - public void spr14949FindsOnInterfaceWithInterfaceProxy() throws InterruptedException { + @Test // SPR-14949 + public void findOnInterfaceWithInterfaceProxy() throws InterruptedException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14949ConfigA.class); AsyncInterface asyncBean = ctx.getBean(AsyncInterface.class); @@ -256,8 +254,8 @@ public class EnableAsyncTests { ctx.close(); } - @Test - public void spr14949FindsOnInterfaceWithCglibProxy() throws InterruptedException { + @Test // SPR-14949 + public void findOnInterfaceWithCglibProxy() throws InterruptedException { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14949ConfigB.class); AsyncInterface asyncBean = ctx.getBean(AsyncInterface.class); diff --git a/spring-tx/src/main/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSource.java b/spring-tx/src/main/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSource.java index b881bb346c8..4761dd510b4 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSource.java +++ b/spring-tx/src/main/java/org/springframework/transaction/annotation/AnnotationTransactionAttributeSource.java @@ -139,14 +139,14 @@ public class AnnotationTransactionAttributeSource extends AbstractFallbackTransa @Override @Nullable - protected TransactionAttribute findTransactionAttribute(Method method) { - return determineTransactionAttribute(method); + protected TransactionAttribute findTransactionAttribute(Class clazz) { + return determineTransactionAttribute(clazz); } @Override @Nullable - protected TransactionAttribute findTransactionAttribute(Class clazz) { - return determineTransactionAttribute(clazz); + protected TransactionAttribute findTransactionAttribute(Method method) { + return determineTransactionAttribute(method); } /** diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java index 2c20f2169c3..b2ebfc12363 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java @@ -55,7 +55,13 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran * Canonical value held in cache to indicate no transaction attribute was * found for this method, and we don't need to look again. */ - private static final TransactionAttribute NULL_TRANSACTION_ATTRIBUTE = new DefaultTransactionAttribute(); + @SuppressWarnings("serial") + private static final TransactionAttribute NULL_TRANSACTION_ATTRIBUTE = new DefaultTransactionAttribute() { + @Override + public String toString() { + return "null"; + } + }; /** @@ -90,7 +96,7 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran // First, see if we have a cached value. Object cacheKey = getCacheKey(method, targetClass); - Object cached = this.attributeCache.get(cacheKey); + TransactionAttribute cached = this.attributeCache.get(cacheKey); if (cached != null) { // Value will either be canonical value indicating there is no transaction attribute, // or an actual transaction attribute. @@ -98,7 +104,7 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran return null; } else { - return (TransactionAttribute) cached; + return cached; } } else { @@ -182,25 +188,22 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran /** - * Subclasses need to implement this to return the transaction attribute - * for the given method, if any. - * @param method the method to retrieve the attribute for - * @return all transaction attribute associated with this method - * (or {@code null} if none) + * Subclasses need to implement this to return the transaction attribute for the + * given class, if any. + * @param clazz the class to retrieve the attribute for + * @return all transaction attribute associated with this class, or {@code null} if none */ @Nullable - protected abstract TransactionAttribute findTransactionAttribute(Method method); + protected abstract TransactionAttribute findTransactionAttribute(Class clazz); /** - * Subclasses need to implement this to return the transaction attribute - * for the given class, if any. - * @param clazz the class to retrieve the attribute for - * @return all transaction attribute associated with this class - * (or {@code null} if none) + * Subclasses need to implement this to return the transaction attribute for the + * given method, if any. + * @param method the method to retrieve the attribute for + * @return all transaction attribute associated with this method, or {@code null} if none */ @Nullable - protected abstract TransactionAttribute findTransactionAttribute(Class clazz); - + protected abstract TransactionAttribute findTransactionAttribute(Method method); /** * Should only public methods be allowed to have transactional semantics? diff --git a/spring-tx/src/test/java/org/springframework/transaction/interceptor/MapTransactionAttributeSource.java b/spring-tx/src/test/java/org/springframework/transaction/interceptor/MapTransactionAttributeSource.java index 4f00f0d3d0a..348a5460b8a 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/interceptor/MapTransactionAttributeSource.java +++ b/spring-tx/src/test/java/org/springframework/transaction/interceptor/MapTransactionAttributeSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 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. @@ -31,23 +31,23 @@ public class MapTransactionAttributeSource extends AbstractFallbackTransactionAt private final Map attributeMap = new HashMap<>(); - public void register(Method method, TransactionAttribute txAttr) { - this.attributeMap.put(method, txAttr); - } - public void register(Class clazz, TransactionAttribute txAttr) { this.attributeMap.put(clazz, txAttr); } - - @Override - protected TransactionAttribute findTransactionAttribute(Method method) { - return this.attributeMap.get(method); + public void register(Method method, TransactionAttribute txAttr) { + this.attributeMap.put(method, txAttr); } + @Override protected TransactionAttribute findTransactionAttribute(Class clazz) { return this.attributeMap.get(clazz); } + @Override + protected TransactionAttribute findTransactionAttribute(Method method) { + return this.attributeMap.get(method); + } + }