Completed backport of lazy CacheManager resolution (including fixed test)
Issue: SPR-12850
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user