Я пытаюсь прочитать некоторые данные из БД и добавить их в кэш.
Вот мои методы.
Код: Выделить всё
public void preloadCache() {
List allData = repository.findAll();
log.info("Data found {}", allData.size());
allData.forEach(cacheService::populateQuarterStatisticCache);
}
Код: Выделить всё
@Service
@Slf4j
public class CacheService {
@CachePut(value = "quarterStatistic", key = "#statistic.type + '-' + #statistic.location")
public QuarterBusinessesStatistic populateQuarterStatisticCache(Statistic statistic) {
log.info("Loading statistic into cache: {}-{}", statistic.getType(), statistic.getLocation());
return statistic.getData();
}
}
Код: Выделить всё
[nio-8080-exec-1] StatisticClient : Data found 1
[nio-8080-exec-1] CacheService : Preloading statistic into cache: restaurant-New York
SpelEvaluationException: EL1007E: свойство или поле «тип» не могут быть найдены в значении null
Если Я меняю ключ в аннотации @CachePut на key = "#statistic?.type + '-' + #statistic?.location", исключений не будет. Но в кеше я увижу сохраненный объект по ключу null-null
Я могу отладить его и увидеть, что мой объект не равен нулю. Журналы также подтверждают это. Но в ключевом выражении оно почему-то равно нулю.
У кого-нибудь было так же?
Примечание: я пробовал изменить ключ на что-то вроде
Код: Выделить всё
#statistic.getType() + '-' + #statistic.getLocation()Подробнее здесь: https://stackoverflow.com/questions/792 ... annotation
Мобильная версия