@Cacheable key use annotation bean in Spring
调用Sping 容器中的bean的中的方法在@Cacheable 的 EL表达式中;
@Service
public class GenerateKey {
public String getKey(){
return "key";
}
}
@Service
public class CacheUtilsService {
//使用public 修饰符
@Autowired
public GenerateKey generateKey ;
@Cacheable(cacheNames = "cacheName", key = "'key'+ #root.target.generateKey.getKey()")
public String getLocationByCode(String code) {
return code;
}
}