当前位置:网站首页>InitializingBean接口及示例
InitializingBean接口及示例
2022-07-28 05:27:00 【yfyh2021】
定义
InitializingBean接口为bean提供了初始化方法的方式,它只包括afterPropertiesSet方法,凡是继承该接口的类,在初始化bean的时候都会执行该方法。
示例
全量数据加载到布隆过滤器中
@Slf4j
@Configuration
public class BloomFilterConfig implements InitializingBean{
@Autowired
private PmsProductService productService;
@Autowired
private RedisTemplate template;
@Bean
public BloomFilterHelper<String> initBloomFilterHelper() {
return new BloomFilterHelper<>((Funnel<String>) (from, into) -> into.putString(from, Charsets.UTF_8)
.putString(from, Charsets.UTF_8), 1000000, 0.01);
}
/**
* 布隆过滤器bean注入
* @return
*/
@Bean
public BloomRedisService bloomRedisService(){
BloomRedisService bloomRedisService = new BloomRedisService();
bloomRedisService.setBloomFilterHelper(initBloomFilterHelper());
bloomRedisService.setRedisTemplate(template);
return bloomRedisService;
}
@Override
public void afterPropertiesSet() throws Exception {
List<Long> list = productService.getAllProductId();
log.info("加载产品到布隆过滤器当中,size:{}",list.size());
if(!CollectionUtils.isEmpty(list)){
list.stream().forEach(item->{
//LocalBloomFilter.put(item);
bloomRedisService().addByBloomFilter(RedisKeyPrefixConst.PRODUCT_REDIS_BLOOM_FILTER,item+"");
});
}
}
}
边栏推荐
猜你喜欢

Bug experience related to IAP jump of stm32

【C笔记】数据类型及存储

redis实现分布式锁思路及redission分布式锁主流程分析

2022-05-24 SpEL使用

Leetcode 刷题日记 剑指 Offer II 053. 二叉搜索树中的中序后继

STM32的IAP跳转相关bug经历

SSAO By Computer Shader(二)
![[队列,栈的简单应用----包装机]](/img/bc/617b1eb35558c4f948018f593a1de5.jpg)
[队列,栈的简单应用----包装机]

关于Shader KeyWord的整理

What are the open earphones? Four types of air conduction earphones with excellent sound quality are recommended
随机推荐
战疫杯--奇奇怪怪的形状
OJ 1284 记数问题
2022-07-19 达梦数据库-实例创建和管理
图形管线基础(二)
江中ACM新生10月26日习题题解
【C笔记】数据类型及存储
2022-05-15 基于jwt令牌token
2022-07-17 达梦数据库安装
js 变量等于0也等也' '问题
Leetcode 刷题日记 剑指 Offer II 050. 向下的路径节点之和
OJ 1131 beautiful number
夹子套利/搬砖套利系统开发
七夕送什么礼物好?小众又高级的产品礼物推荐
SSAO By Computer Shader(二)
What's a good gift for your girlfriend on the Chinese Valentine's day in 2022? Practical and beautiful gift recommendation
Leetcode 刷题日记 剑指 Offer II 047. 二叉树剪枝
OJ 1089 Spring Festival travel
Antenna effect solution
2022-07-19 达梦数据库 连接实例、执行脚本、系统命令
Leetcode brush questions diary sword finger offer II 047. Binary tree pruning