使用SpringBoot整合SpringCache+Redis遇到的坑

使用 SpringCache 的时候未给 cacheNames 赋值报错

java.lang.IllegalStateException: No cache could be resolved for ‘Builder[public cn.jump.mapper.user.User cn.jump.user.UserServiceImpl.get(long)] caches=[] | key=’#userId+‘User’’ | keyGenerator=’’ | cacheManager=’’ | cacheResolver=’’ | condition=’’ | unless=’#result == null’ | sync=‘false’’ using resolver ‘org.springframework.cache.interceptor.SimpleCacheResolver@6305946e’. At least one cache should be provided per cache operation.
at org.springframework.cache.interceptor.CacheAspectSupport.getCaches(CacheAspectSupport.java:226) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]

	@Cacheable(cacheNames = "user", key = "#userId+'User'", unless = "#result == null")
	@Override
	public User get(long userId) {
		return userMapper.get(userId);
	}

需要给 cacheNames 这个属性赋值,否则会抛异常.

你可能感兴趣的:(Redis)