Completed backport of lazy CacheManager resolution (including fixed test)

Issue: SPR-12850
This commit is contained in:
Juergen Hoeller
2015-08-26 09:55:11 +02:00
parent 49161da403
commit 7aa3175a71
2 changed files with 38 additions and 7 deletions

View File

@@ -61,10 +61,12 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests {
return new AnnotationConfigApplicationContext(EnableCachingConfig.class);
}
@Test
public void fullCachingConfig() throws Exception {
AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(FullCachingConfig.class);
DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
assertSame(context.getBean(KeyGenerator.class), cos.getKeyGenerator());
assertSame(context.getBean("cacheResolver", CacheResolver.class),
@@ -102,16 +104,15 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests {
}
@Test
public void exceptionCacheResolverFallbacksToMainOne() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(
NoExceptionCacheResolverConfig.class);
public void exceptionCacheResolverLazilyRequired() {
ConfigurableApplicationContext context =
new AnnotationConfigApplicationContext(NoExceptionCacheResolverConfig.class);
try {
DefaultJCacheOperationSource cos = context.getBean(DefaultJCacheOperationSource.class);
assertSame(context.getBean("cacheResolver"), cos.getCacheResolver());
assertNull(cos.getExceptionCacheResolver());
JCacheableService<?> service = context.getBean(JCacheableService.class);
service.cache("id");
// This call requires the cache manager to be set
@@ -150,11 +151,11 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests {
}
}
@Configuration
@EnableCaching
public static class FullCachingConfig implements JCacheConfigurer {
@Override
@Bean
public CacheManager cacheManager() {
@@ -186,6 +187,7 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests {
}
}
@Configuration
@EnableCaching
public static class EmptyConfigSupportConfig extends JCacheConfigurerSupport {
@@ -195,6 +197,7 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests {
}
}
@Configuration
@EnableCaching
static class FullCachingConfigSupport extends JCacheConfigurerSupport {
@@ -224,6 +227,7 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests {
}
}
@Configuration
@EnableCaching
static class NoExceptionCacheResolverConfig extends JCacheConfigurerSupport {