@Cacheable()返回ID为null

时间:2019-01-23 09:47:57

标签: spring caching hazelcast spring-cache

我有一个方法findAll()从BD返回所有专业,在此方法中,我放置了注释@Cacheable以从缓存中获取数据,问题是当我执行{{1 }} API,我第一次获得正确的数据,第二次执行API时,获得的ID为空ID

/specialities

配置

@Service
@CacheConfig(cacheNames = ServiceConstant.SPECIALITY)
public class SpecialityServiceImpl implements SpecialityService {

    @Autowired
    private SpecialitySearchRepository specialitySearchRepository;

    @Autowired
    private SpecialtyMapper specialityMapper;

    @Override
    @Cacheable
    public List<SpecialityDTO> findAll() {
        return specialitySearchRepository.findAll().stream().map(specialityMapper::toDto)
                .collect(Collectors.toCollection(LinkedList::new));
    }

}

@RestController
public class SpecialityResource {

    @Autowired
    private SpecialityService specialityService;

    @GetMapping("/specialities")
    public List<SpecialityDTO> getAllSpecialitys() {
        return specialityService.findAll();
    }

}

1 个答案:

答案 0 :(得分:1)

@Aymen Kanzari,请参阅:https://gist.github.com/gokhanoner/766a1a807744d1a69c6a7799c3f34d73

我试图复制该问题,但它似乎按预期工作。我可以看到inside findAll method是第一个呼叫,但是接下来的呼叫只是访问了Hazelcast缓存。您能再描述一下这个问题吗?