@CacheConfig(cacheNames) broken when used on interface [SPR-14781] #19347
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: regression
A bug that is also a regression
Milestone
Marc Vanbrabant opened SPR-14781 and commented
Since upgrading from 4.1 to 4.3 we are seeing the following exception thrown in CacheAspectSupport.getCaches when a call to a
@Cacheable
method occurs:As far as I have been able to trace, it looks like the refactoring from #18054 (59c88eb) might be the cause.
It seems to fail when the
@CacheConfig
annotation is not on the Impl class of the interface, but on the interface itself.We observe the same error if the
@Cachable
annotation is placed on the UserServiceImpl class:Moving down the
@CacheConfig
down to the UserServiceImpl class circumvents the issue.The difference compared to 4.1 (as far as I was manage to debug), seem to be that SpringCacheAnnotationParser.parseCacheAnnotations() now uses AnnotatedElementUtils.findAllMergedAnnotations(ae, CacheEvict.class)
In 4.1 SpringCacheAnnotationParser.parseCacheAnnotations() would return null when called with the UserServiceImpl.getUserByUsername as second argument. It would then return null all the way up to AbstractFallbackCacheOperationSource.computeCacheOperations() where it would fallback onto the following check:
The method here being the interface method.
https://github.com/spring-projects/spring-framework/blob/4.1.x/spring-context/src/main/java/org/springframework/cache/interceptor/AbstractFallbackCacheOperationSource.java#L146
In 4.3 it seems that SpringCacheAnnotationParser.parseCacheAnnotations() does not return null and that the defaultConfig of the interface is not merged with parsed annotations from the Impl method.
Note:
If this is indeed a bug, the workaround is to put the
@CacheConfig
on the implementing classes, or specify the cacheNames in the@Cacheable
annotationsAffects: 4.3.2
Issue Links:
@Cache
* as merged composed annotationsReferenced from: commits 08972ef, 3cca57a
0 votes, 5 watchers
The text was updated successfully, but these errors were encountered: