From d69fb06852a8594db1338dc92799e857e0cc7bc8 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 28 Feb 2017 13:08:55 +0100 Subject: [PATCH] Skip transaction/caching metadata retrieval for java.lang.Object methods Also retrieves CacheConfig as merged annotation now, aligned with other caching annotations. Issue: SPR-15296 (cherry picked from commit d4a1b59) --- .../cache/annotation/SpringCacheAnnotationParser.java | 5 ++--- .../AbstractFallbackCacheOperationSource.java | 6 +++++- .../AbstractFallbackTransactionAttributeSource.java | 9 +++++++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java b/spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java index 3a024e0faa..998b59a146 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -28,7 +28,6 @@ import org.springframework.cache.interceptor.CacheOperation; import org.springframework.cache.interceptor.CachePutOperation; import org.springframework.cache.interceptor.CacheableOperation; import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.core.annotation.AnnotationUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -194,7 +193,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria * @return the default config (never {@code null}) */ DefaultCacheConfig getDefaultCacheConfig(Class target) { - CacheConfig annotation = AnnotationUtils.getAnnotation(target, CacheConfig.class); + CacheConfig annotation = AnnotatedElementUtils.getMergedAnnotation(target, CacheConfig.class); if (annotation != null) { return new DefaultCacheConfig(annotation.cacheNames(), annotation.keyGenerator(), annotation.cacheManager(), annotation.cacheResolver()); 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 88d0aec5f7..086603f1f9 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -84,6 +84,10 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera */ @Override public Collection getCacheOperations(Method method, Class targetClass) { + if (method.getDeclaringClass() == Object.class) { + return null; + } + Object cacheKey = getCacheKey(method, targetClass); Collection cached = this.attributeCache.get(cacheKey); 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 861502af3d..68131701ca 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -69,7 +69,8 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran *

As this base class is not marked Serializable, the cache will be recreated * after serialization - provided that the concrete subclass is Serializable. */ - final Map attributeCache = new ConcurrentHashMap(1024); + private final Map attributeCache = + new ConcurrentHashMap(1024); /** @@ -82,6 +83,10 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran */ @Override public TransactionAttribute getTransactionAttribute(Method method, Class targetClass) { + if (method.getDeclaringClass() == Object.class) { + return null; + } + // First, see if we have a cached value. Object cacheKey = getCacheKey(method, targetClass); Object cached = this.attributeCache.get(cacheKey);