[英]Spring Boot Cache SpEL (#result) Returns Null
我有一個Spring Boot RESTful API,用於接收和發送SMS到客戶端。 我的應用程序連接到我們本地的SMS服務器,並通過移動運營商接收SMS並將其推送給客戶端。 我的應用程序運行良好。 但是我想通過實現緩存來優化我的應用程序。 我正在使用Spring Boot的簡單緩存。 創建新的SMS時,我面臨一些挑戰。
所有發送/接收的SMS都以對話的形式(每張票),並且已附加了客戶端。 因此,我很難將客戶端保存到緩存中。 以下是createClient()代碼段:
@Transactional
@Caching(evict = {
@CacheEvict("allClientsPage"),
@CacheEvict("countClients")
}, put = {
@CachePut(value = "clients", key = "#result.id", unless="#result != null"),
@CachePut(value = "clientsByPhone", key = "#result.phoneNumber", unless="#result != null")
})
public Client create(Client client) {
Client c = new Client();
if (client.getName() != null) c.setName(client.getName().trim());
c.setPhoneNumber(client.getPhoneNumber().trim());
/**---***/
c.setCreatedAt(new Date());
return clientRepository.save(c);
}
當我嘗試創建新客戶端時,
org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'id' cannot be found on null
被拋出。
任何幫助將不勝感激。
而不是使用unless="# result! = null"
而是使用condition="#result != null"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.