美文网首页
springboot 多数据源 health

springboot 多数据源 health

作者: Lonely_Acmen | 来源:发表于2018-03-28 19:00 被阅读0次

基于公司多库使用的框架,导致health接口报错,作词处理。
主要实现方式,就是在做db健康监测的时候预先处理下routerkey。
注意:
1 afterPropertiesSet方法不可省略

import javax.sql.DataSource;
 
 
import org.springframework.beans.factory.InitializingBean;
 
import org.springframework.beans.factory.annotation.Autowired;
 
import org.springframework.boot.actuate.health.DataSourceHealthIndicator;
 
import org.springframework.boot.actuate.health.Health.Builder;
 
import org.springframework.stereotype.Component;
 
import com.hualala.app.promotion.utils.InterceptorConstant;
 
import com.hualala.commons.multidatasource.holder.DataSourceContextHolder;
 
 
@Component("dbHealthIndicator")
 
public class PromotionDbHealthIndicator extends DataSourceHealthIndicator implements InitializingBean{
 
    @Autowired
 
    private DataSource mySource;
 
 
    @Override
 
    protected void doHealthCheck(Builder builder) throws Exception {
 
        String key = InterceptorConstant.STR + 10890;
 
        DataSourceContextHolder.setDataSourceType(key);
 
         
 
        setDataSource(mySource);
 
        super.doHealthCheck(builder);
 
    }
 
    @Override
 
    public void afterPropertiesSet() throws Exception {
 
    }
 
}

相关文章

网友评论

      本文标题:springboot 多数据源 health

      本文链接:https://www.haomeiwen.com/subject/xppucftx.html