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