实现InitializingBean接口,并重写afterPropertiesSet()方法
public class xxxController implements InitializingBean{
public void afterPropertiesSet() throws Exception {
List<GoodsVo> goodsList = goodsService.listGoodsVo();
if(goodsList == null) {
return;
}
for(GoodsVo goods : goodsList) {
redisService.set(GoodsKey.getMiaoshaGoodsStock, ""+goods.getId(), goods.getStockCount());
localOverMap.put(goods.getId(), false);
}
}
}
本文介绍了一个Spring应用中如何通过实现InitializingBean接口并重写afterPropertiesSet()方法来完成应用程序启动时从数据库加载商品库存到Redis缓存的过程。该方法首先获取商品列表,然后将每个商品的库存数量设置到Redis中。

被折叠的 条评论
为什么被折叠?



