Ich versuche, Short
Wert mit @Cacheable
zu cachen.Wie verwende ich Short Datentyp mit @Cacheable?
@EnableAutoConfiguration
@EnableCaching
public class Config {
@Bean
public CacheManager cacheManager() {
return new ConcurrentMapCacheManager();
}
}
@Service
public class MyCacheService {
@Cacheable("testcache")
public Short getId(String name) {
return 1;
}
}
Ergebnis:
java.lang.NullPointerException
at org.springframework.cache.interceptor.AbstractCacheResolver.resolveCaches(AbstractCacheResolver.java:78) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.cache.interceptor.CacheAspectSupport.getCaches(CacheAspectSupport.java:216) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContext.<init>(CacheAspectSupport.java:565) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.cache.interceptor.CacheAspectSupport.getOperationContext(CacheAspectSupport.java:229) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContexts.<init>(CacheAspectSupport.java:508) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:302) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:61) ~[spring-context-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655) ~[spring-aop-4.2.6.RELEASE.jar:4.2.6.RELEASE]
Dieses geworfen wird, weil cacheManager
ist null
in AbstractCacheResolver
. Aber warum?
Haben Sie die Annotation @Configuration? – Jango
ja oder natürlich habe ich es. – membersound