您的位置:首页 > 编程语言 > Java开发

Spring实现数据库的初始化

2012-08-27 10:36 134 查看
本来转载于/article/4483601.html

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(){

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: