[Exception resolution] Cache error: Null key returned for cache operation (maybe you are using named params on classes without

15942001:

1. Background description

Technology stack: Springboot(2.5.14) + MQTT(5.x) + Cache + MySQL

There is a method in the project: query device details according to the device id, which is a very frequently used function. In order to reduce the pressure on the database, it is natural to think of using caching technology.

insert image description here

2. Error content

insert image description here

Null key returned for cache operation (maybe you are using named params on classes without debug info?) Builder

The detailed error information is shown in the figure below:

insert image description here

Three, the reason for the error

insert image description here

@Cacheable(key = "#id", unless = "#result==null")

The value of the key in the annotation, that is, the id value is null, that is, the input parameter id of the method is empty. When calling the method, a null value cannot be passed. If a null value is passed in, the above error will be reported.

4. Solutions

When calling this method, first determine whether the id is empty, and then call this method when the id is not empty.

for example:
insert image description here

This article is over!

Guess you like

Origin blog.csdn.net/weixin_44299027/article/details/131978708