基于公司多庫(kù)使用的框架侈沪,導(dǎo)致health接口報(bào)錯(cuò),作詞處理仁讨。
主要實(shí)現(xiàn)方式随珠,就是在做db健康監(jiān)測(cè)的時(shí)候預(yù)先處理下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 {
}
}