Fix cache annotation tip

Even if using cglib proxy mode, annotations on an interface can be recognized.

Signed-off-by: Kwangyong Kim <banana.yong@gmail.com>
This commit is contained in:
Kwangyong Kim
2021-11-24 16:41:10 +09:00
committed by Juergen Hoeller
parent 2fb3f9993f
commit ceea00f733
2 changed files with 41 additions and 5 deletions

View File

@@ -73,6 +73,19 @@ public class EnableCachingIntegrationTests {
fooGetSimple(service);
}
@Test
public void barServiceWithCacheableInterfaceCglib() {
this.context = new AnnotationConfigApplicationContext(BarConfigCglib.class);
BarService service = this.context.getBean(BarService.class);
Cache cache = getCache();
Object key = new Object();
assertCacheMiss(key, cache);
Object value = service.getSimple(key);
assertCacheHit(key, value, cache);
}
private void fooGetSimple(FooService service) {
Cache cache = getCache();
@@ -184,6 +197,31 @@ public class EnableCachingIntegrationTests {
}
}
@Configuration
@Import(SharedConfig.class)
@EnableCaching(proxyTargetClass = true)
static class BarConfigCglib {
@Bean
public BarService barService() {
return new BarServiceImpl();
}
}
interface BarService {
@Cacheable(cacheNames = "testCache")
Object getSimple(Object key);
}
static class BarServiceImpl implements BarService {
private final AtomicLong counter = new AtomicLong();
@Override
public Object getSimple(Object key) {
return this.counter.getAndIncrement();
}
}
@Configuration
@Import(FooConfig.class)