Spring实现数据库的初始化
2012-08-27 10:36
134 查看
本来转载于/article/4483601.html
1.实现SmartLifecycle接口
2.实现ApplicationListener接口,定义个event,判断event是否相等。
1.实现SmartLifecycle接口
public class InitRedisCache implements SmartLifecycle{ @Override public void start() { // TODO Auto-generated method stub } @Override public void stop() { // TODO Auto-generated method stub } @Override public boolean isRunning() { // TODO Auto-generated method stub return false; } @Override public int getPhase() { // TODO Auto-generated method stub return 0; } @Override public boolean isAutoStartup() { // TODO Auto-generated method stub return true; } @Override public void stop(Runnable callback) { // TODO Auto-generated method stub } }
2.实现ApplicationListener接口,定义个event,判断event是否相等。
@Lazy(false) @Repository public class InitRedisCache implements ApplicationListener{ @Autowired @Qualifier("dictionaryService") private DictionaryService dictionaryService; @Autowired @Qualifier("redisService") private RedisService redisService; @Override public void onApplicationEvent(ApplicationEvent event) { if(event instanceof InitEvent){ initDictionaryData(); } } public void initDictionaryData(){ } }
相关文章推荐
- Spring技术内幕——深入解析Spring架构与设计原理(三)数据库的操作实现
- Spring 实现数据库读写分离
- Spring 实现数据库读写分离
- Spring实现数据库读写分离
- 本文主要介绍使用SpringBoot与shiro实现基于数据库的细粒度动态权限管理系统实例。
- Spring 实现数据库读写分离
- Maven + Spring MVC+Mybatis + MySQL +AngularJS + Bootstrap 实现简单微博应用(二)访问数据库
- 实现Spring连接数据库
- Kotlin整合Spring Boot实现数据库增删改查(mybatis版)
- Spring+Mybatis 实现aop数据库读写分离与多数据库源配置操作
- Spring 配置多数据源实现数据库读写分离
- SpringMVC+mybatis实现图片文本同时上传并储存数据库中
- SpringBoot实现数据库密码的加密操作
- Spring Boot中使用Spring-data-jpa实现数据库增删查改
- Spring 实现数据库读写分离
- Spring3.1.0实现原理分析(十二).MVC核心类DispatcherServlet初始化过程
- Spring bean 通过实现 InitializingBean ,DisposableBean 接口实现初始化方法和销毁前操作
- Spring实现数据库的读写分离
- Spring3 整合 Hibernate4实现数据库操作(1)
- spring+spring mvc +mybatis+druid 实现数据库主从分离