我有一個 Spring Boot RESTful API 來接收和發送 SMS 給客戶端。我的應用程序連接到我們的本地短信服務器,并通過移動運營商接收短信并將其推送給客戶。我的應用程序運行良好。但我想通過實現緩存來優化我的應用程序。我正在使用 Spring Boot 的簡單緩存。創建新短信時我面臨一些挑戰。發送/接收的所有 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被拋出。
添加回答
舉報
0/150
提交
取消