下面列出了怎么用org.springframework.cache.interceptor.CacheErrorHandler的API类实例代码及写法,或者点击链接到github查看源代码。
@Before
public void setup() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
this.cache = context.getBean("mockCache", Cache.class);
this.errorCache = context.getBean("mockErrorCache", Cache.class);
this.errorHandler = context.getBean(CacheErrorHandler.class);
this.simpleService = context.getBean(SimpleService.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),
cos.getCacheResolver());
assertSame(context.getBean("exceptionCacheResolver", CacheResolver.class),
cos.getExceptionCacheResolver());
JCacheInterceptor interceptor = context.getBean(JCacheInterceptor.class);
assertSame(context.getBean("errorHandler", CacheErrorHandler.class), interceptor.getErrorHandler());
}
@Before
public void setup() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
this.cache = context.getBean("mockCache", Cache.class);
this.errorCache = context.getBean("mockErrorCache", Cache.class);
this.errorHandler = context.getBean(CacheErrorHandler.class);
this.simpleService = context.getBean(SimpleService.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),
cos.getCacheResolver());
assertSame(context.getBean("exceptionCacheResolver", CacheResolver.class),
cos.getExceptionCacheResolver());
JCacheInterceptor interceptor = context.getBean(JCacheInterceptor.class);
assertSame(context.getBean("errorHandler", CacheErrorHandler.class), interceptor.getErrorHandler());
}
@Before
public void setup() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
this.cache = context.getBean("mockCache", Cache.class);
this.errorHandler = context.getBean(CacheErrorHandler.class);
this.simpleService = context.getBean(SimpleService.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),
cos.getCacheResolver());
assertSame(context.getBean("exceptionCacheResolver", CacheResolver.class),
cos.getExceptionCacheResolver());
JCacheInterceptor interceptor = context.getBean(JCacheInterceptor.class);
assertSame(context.getBean("errorHandler", CacheErrorHandler.class), interceptor.getErrorHandler());
}
@Override
@Nullable
public CacheErrorHandler errorHandler() {
return null;
}
@Test
public void testCacheErrorHandler() {
CacheInterceptor ci = this.ctx.getBean(
"org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class);
assertSame(this.ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler());
}
@Test
public void testCacheErrorHandler() {
CacheInterceptor ci = this.ctx.getBean(CacheInterceptor.class);
assertSame(this.ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler());
}
@Override
@Bean
public CacheErrorHandler errorHandler() {
return new SimpleCacheErrorHandler();
}
protected AbstractCacheInterceptor(CacheErrorHandler errorHandler) {
super(errorHandler);
}
public CacheResultInterceptor(CacheErrorHandler errorHandler) {
super(errorHandler);
}
protected CacheRemoveEntryInterceptor(CacheErrorHandler errorHandler) {
super(errorHandler);
}
protected AbstractKeyCacheInterceptor(CacheErrorHandler errorHandler) {
super(errorHandler);
}
protected CacheRemoveAllInterceptor(CacheErrorHandler errorHandler) {
super(errorHandler);
}
public CachePutInterceptor(CacheErrorHandler errorHandler) {
super(errorHandler);
}
@Bean
@Override
public CacheErrorHandler errorHandler() {
return mock(CacheErrorHandler.class);
}
@Override
@Bean
public CacheErrorHandler errorHandler() {
return new SimpleCacheErrorHandler();
}
@Test
public void testCacheErrorHandler() {
JCacheInterceptor ci = ctx.getBean(JCacheInterceptor.class);
assertSame(ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler());
}
@Override
@Bean
public CacheErrorHandler errorHandler() {
return new SimpleCacheErrorHandler();
}
@Test
public void testCacheErrorHandler() {
load(EnableCachingConfig.class);
AnnotationCacheAspect aspect = this.ctx.getBean(AnnotationCacheAspect.class);
assertSame(this.ctx.getBean("errorHandler", CacheErrorHandler.class), aspect.getErrorHandler());
}
@Override
@Bean
public CacheErrorHandler errorHandler() {
return new SimpleCacheErrorHandler();
}
@Override
public CacheErrorHandler errorHandler() {
return new CustomCacheErrorHandler();
}
@Override
@Nullable
public CacheErrorHandler errorHandler() {
return null;
}
@Test
public void testCacheErrorHandler() {
CacheInterceptor ci = this.ctx.getBean(
"org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class);
assertSame(this.ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler());
}
@Test
public void testCacheErrorHandler() {
CacheInterceptor ci = this.ctx.getBean(CacheInterceptor.class);
assertSame(this.ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler());
}
@Override
@Bean
public CacheErrorHandler errorHandler() {
return new SimpleCacheErrorHandler();
}
protected AbstractCacheInterceptor(CacheErrorHandler errorHandler) {
super(errorHandler);
}
public CacheResultInterceptor(CacheErrorHandler errorHandler) {
super(errorHandler);
}
protected CacheRemoveEntryInterceptor(CacheErrorHandler errorHandler) {
super(errorHandler);
}