Skip to content

Commit d69fb06

Browse files
committed
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)
1 parent e9de3bb commit d69fb06

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,6 @@
2828
import org.springframework.cache.interceptor.CachePutOperation;
2929
import org.springframework.cache.interceptor.CacheableOperation;
3030
import org.springframework.core.annotation.AnnotatedElementUtils;
31-
import org.springframework.core.annotation.AnnotationUtils;
3231
import org.springframework.util.ObjectUtils;
3332
import org.springframework.util.StringUtils;
3433

@@ -194,7 +193,7 @@ Collection<CacheOperation> parseCachingAnnotation(AnnotatedElement ae, DefaultCa
194193
* @return the default config (never {@code null})
195194
*/
196195
DefaultCacheConfig getDefaultCacheConfig(Class<?> target) {
197-
CacheConfig annotation = AnnotationUtils.getAnnotation(target, CacheConfig.class);
196+
CacheConfig annotation = AnnotatedElementUtils.getMergedAnnotation(target, CacheConfig.class);
198197
if (annotation != null) {
199198
return new DefaultCacheConfig(annotation.cacheNames(), annotation.keyGenerator(),
200199
annotation.cacheManager(), annotation.cacheResolver());

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -84,6 +84,10 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
8484
*/
8585
@Override
8686
public Collection<CacheOperation> getCacheOperations(Method method, Class<?> targetClass) {
87+
if (method.getDeclaringClass() == Object.class) {
88+
return null;
89+
}
90+
8791
Object cacheKey = getCacheKey(method, targetClass);
8892
Collection<CacheOperation> cached = this.attributeCache.get(cacheKey);
8993

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -69,7 +69,8 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran
6969
* <p>As this base class is not marked Serializable, the cache will be recreated
7070
* after serialization - provided that the concrete subclass is Serializable.
7171
*/
72-
final Map<Object, TransactionAttribute> attributeCache = new ConcurrentHashMap<Object, TransactionAttribute>(1024);
72+
private final Map<Object, TransactionAttribute> attributeCache =
73+
new ConcurrentHashMap<Object, TransactionAttribute>(1024);
7374

7475

7576
/**
@@ -82,6 +83,10 @@ public abstract class AbstractFallbackTransactionAttributeSource implements Tran
8283
*/
8384
@Override
8485
public TransactionAttribute getTransactionAttribute(Method method, Class<?> targetClass) {
86+
if (method.getDeclaringClass() == Object.class) {
87+
return null;
88+
}
89+
8590
// First, see if we have a cached value.
8691
Object cacheKey = getCacheKey(method, targetClass);
8792
Object cached = this.attributeCache.get(cacheKey);

0 commit comments

Comments
 (0)