Defend against lambda transaction customizers
Update `CacheManagerCustomizers` to deal directly with `ClassCastException` assuming that they are because a customizer is implemented using a lambda. Closes gh-7788
This commit is contained in:
parent
1f5970c537
commit
1fa8b1ac91
|
@ -21,6 +21,9 @@ import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
import org.springframework.beans.BeansException;
|
||||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||||
import org.springframework.cache.CacheManager;
|
import org.springframework.cache.CacheManager;
|
||||||
|
@ -38,6 +41,8 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
||||||
*/
|
*/
|
||||||
class CacheManagerCustomizers implements ApplicationContextAware {
|
class CacheManagerCustomizers implements ApplicationContextAware {
|
||||||
|
|
||||||
|
private static final Log logger = LogFactory.getLog(CacheManagerCustomizers.class);
|
||||||
|
|
||||||
private ConfigurableApplicationContext applicationContext;
|
private ConfigurableApplicationContext applicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,11 +58,27 @@ class CacheManagerCustomizers implements ApplicationContextAware {
|
||||||
cacheManager);
|
cacheManager);
|
||||||
AnnotationAwareOrderComparator.sort(customizers);
|
AnnotationAwareOrderComparator.sort(customizers);
|
||||||
for (CacheManagerCustomizer<CacheManager> customizer : customizers) {
|
for (CacheManagerCustomizer<CacheManager> customizer : customizers) {
|
||||||
customizer.customize(cacheManager);
|
customize(cacheManager, customizer);
|
||||||
}
|
}
|
||||||
return cacheManager;
|
return cacheManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
|
private void customize(CacheManager cacheManager,
|
||||||
|
CacheManagerCustomizer customizer) {
|
||||||
|
try {
|
||||||
|
customizer.customize(cacheManager);
|
||||||
|
}
|
||||||
|
catch (ClassCastException ex) {
|
||||||
|
// Possibly a lambda-defined listener which we could not resolve the generic
|
||||||
|
// event type for
|
||||||
|
if (logger.isDebugEnabled()) {
|
||||||
|
logger.debug("Non-matching transaction manager type for customizer: "
|
||||||
|
+ customizer, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||||
private List<CacheManagerCustomizer<CacheManager>> findCustomizers(
|
private List<CacheManagerCustomizer<CacheManager>> findCustomizers(
|
||||||
CacheManager cacheManager) {
|
CacheManager cacheManager) {
|
||||||
|
|
Loading…
Reference in New Issue