下面的类中有一个方法:
@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 在 TRACE 级别内部记录其缓存工作流。要启用此功能,请在您的 application.properties 文件中包含以下内容。
logging.level.org.springframework.cache=TRACE
关于java - 如何通过@Cacheable 注解记录缓存命中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55352450/