我正在尝试使用单个redis缓存来存储两个GET服务的响应-一个是POST,一个是GET。对于GET服务,没有请求参数可以用来在Redis中存储Webservice的响应,当我尝试用硬编码的Key存储它时,它给出了下面的错误。
null key returned for cache operation (maybe you are using named params on classes without debug info?) Builder[public java.util.Map com.getResponse() throws com.adapter.framework.assetserviceadaptor.exception.ServiceExceptions] caches=[redis-cache] | key='#AssetCache' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='false'这就是我尝试存储GET服务响应的方式
@Cacheable(value="redis-cache",key ="#AssetCache")
public Map<String, AssetDetailBO> getAssetsResponse() throws COAssetServiceExceptions {
try {
log.info("---- CO_STAGE=[ Caching Service ] ---- ");
return mergingBrokerageAndMutulFund(assetServiceImpl.getAssetResponse());
} catch (ServiceExceptions e) {
log.info("---- CO_STAGE=[ Exception while Calling Assets Adapter For COT ] ---- "
+ e.getErrorMessage());
throw e;
}
}这就是我存储POST服务响应的方式,它工作得很好。
@Cacheable(value="redis-cache",key ="#customerId")
public CustomerDTO retriveCustomerdetails( String customerId, String modelId,
String requestId) throws COException {
CustomerInfo csDTO;
try {
csDTO = csDTOAdapterImpl.
getCustomerDetails(customerId);
} catch (Exception e) {
e.printStackTrace();
}
return csDTO;
}发布于 2020-04-12 22:33:18
您可以使用不带值的@Cacheable和其他属性,如@Cacheable("all-students")
示例:
@GetMapping("/student/{id}")
@Cacheable(value = "post-single", key = "#id")
public Student findStudentById(@PathVariable String id) {
System.out.println("Searching by ID : " + id);
return studentService.getStudentByID(id);
}
@GetMapping("/students")
@Cacheable("all-students")
public List<Student> getAllStudents() {
List<Student> _ = new ArrayList<>();
_.add(studentService.getStudentByID("1"));
return _;
}发布于 2020-04-14 21:40:52
设置不带#的常量关键点,如下所示:
@Cacheable(value="redis-cache",key ="'AssetCache'")
public Map<String, AssetDetailBO> getAssetsResponse() throws COAssetServiceExceptions {
try {
log.info("---- CO_STAGE=[ Caching Service ] ---- ");
return mergingBrokerageAndMutulFund(assetServiceImpl.getAssetResponse());
} catch (ServiceExceptions e) {
log.info("---- CO_STAGE=[ Exception while Calling Assets Adapter For COT ] ---- "
+ e.getErrorMessage());
throw e;
}
}https://stackoverflow.com/questions/61121093
复制相似问题