Prevent early bean initialization with @EnableCaching

Prior to this commmit, any configuration class holding a CacheManager
bean would be eagerly instantiated. This is because the
CacheConfiguration infrastructure requests all beans of type
CacheManager.

This commit defers the resolution of the CacheManager as late
as possible.

Issue: SPR-12336
This commit is contained in:
Stephane Nicoll
2014-10-15 14:19:28 +02:00
parent 8e5c77dc11
commit 5aefcc802e
5 changed files with 64 additions and 67 deletions

View File

@@ -19,6 +19,8 @@ package org.springframework.cache.config;
import org.junit.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.CacheTestUtils;
import org.springframework.cache.annotation.CachingConfigurerSupport;
@@ -73,7 +75,7 @@ public class EnableCachingTests extends AbstractAnnotationTests {
ctx.refresh();
}
@Test(expected=IllegalStateException.class)
@Test(expected=NoUniqueBeanDefinitionException.class)
public void multipleCacheManagerBeans() throws Throwable {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(MultiCacheManagerConfig.class);
@@ -106,7 +108,7 @@ public class EnableCachingTests extends AbstractAnnotationTests {
}
}
@Test(expected=IllegalStateException.class)
@Test(expected=NoSuchBeanDefinitionException.class)
public void noCacheManagerBeans() throws Throwable {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(EmptyConfig.class);