Search code examples
springspring-bootspring-mvcspring-data-jpaspring-cache

SpringBoot 2.1.4.RELEASE not to cache null value in @Cacheable annotation


I have an SpringBoot 2.1.4.RELEASE app. with a repository:

@Repository
public interface PercentageAlertXMenuRepository extends CrudRepository<PercentageAlertXMenu, Long> {

    @Cacheable("percentageAlertXMenu", unless="#result == null")
    PercentageAlertXMenu findByPercentageAlertAndMenu (MenuPercentageAlert percentageAlert, Menu Menu);

but I got a compilation error:

Syntax error on token ""percentageAlertXMenu"", invalid 
 MemberValuePairs

Solution

  • You need to use the value attribute of the annotation:

    @Cacheable(value="percentageAlertXMenu", unless="#result == null")