Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 如何通过@Cacheable注释记录缓存命中?_Spring_Spring Cache - Fatal编程技术网

Spring 如何通过@Cacheable注释记录缓存命中?

Spring 如何通过@Cacheable注释记录缓存命中?,spring,spring-cache,Spring,Spring Cache,在下面这样的类中有一个方法: @Override @Transactional @Cacheable(value = "products", key = "#id") public Product getProduct(long id) throws ApplicationException { Product product = null; try { ProductEntity productEntity

在下面这样的类中有一个方法:

    @Override
    @Transactional
    @Cacheable(value = "products", key = "#id")
    public Product getProduct(long id) throws ApplicationException {
        Product product = null;
        try {
            ProductEntity productEntity = productDAO.getProduct(id);
            product = productTransformer.toProduct(productEntity);
        } catch (SystemException ex) {
            throw new ApplicationException(ex.getCode(), ex.getMessage(), "Problem in DataLayer", "Data Layer Error",
                    new Object[] { ex });
        }
        return product;
    }
应用程序运行良好。但是当数据被放入缓存时,我希望有一个缓存命中日志。我想通过log4j.properties记录它。


如何配置application.properties以便记录它?

Spring在跟踪级别内部记录其缓存工作流。要启用此功能,请在application.properties文件中包括以下内容

logging.level.org.springframework.cache=TRACE


包括以下内容应该会有所帮助:

logging.level.org.springframework.cache=TRACE