diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java index 4d7d8564d2..c528a83206 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 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. @@ -221,11 +221,11 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker } catch (NoUniqueBeanDefinitionException ex) { throw new IllegalStateException("No CacheResolver specified, and no unique bean of type " + - "CacheManager found. Mark one as primary or declare a specific CacheManager to use."); + "CacheManager found. Mark one as primary or declare a specific CacheManager to use.", ex); } catch (NoSuchBeanDefinitionException ex) { throw new IllegalStateException("No CacheResolver specified, and no bean of type CacheManager found. " + - "Register a CacheManager bean or remove the @EnableCaching annotation from your configuration."); + "Register a CacheManager bean or remove the @EnableCaching annotation from your configuration.", ex); } } this.initialized = true; diff --git a/spring-context/src/test/java/org/springframework/cache/config/EnableCachingTests.java b/spring-context/src/test/java/org/springframework/cache/config/EnableCachingTests.java index fae93b5a59..ea77174789 100644 --- a/spring-context/src/test/java/org/springframework/cache/config/EnableCachingTests.java +++ b/spring-context/src/test/java/org/springframework/cache/config/EnableCachingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 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. @@ -19,6 +19,8 @@ package org.springframework.cache.config; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanCreationException; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.NoUniqueBeanDefinitionException; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.annotation.EnableCaching; @@ -87,6 +89,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests { } catch (IllegalStateException ex) { assertThat(ex.getMessage().contains("no unique bean of type CacheManager")).isTrue(); + assertThat(ex).hasCauseInstanceOf(NoUniqueBeanDefinitionException.class); } } @@ -121,6 +124,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests { } catch (IllegalStateException ex) { assertThat(ex.getMessage().contains("no bean of type CacheManager")).isTrue(); + assertThat(ex).hasCauseInstanceOf(NoSuchBeanDefinitionException.class); } }