use of io.seata.config.ConfigType in project chao-cloud by chaojunzi.
the class TxSeataImportSelector method selectImports.
@Override
public String[] selectImports(AnnotationMetadata metadata) {
Class<Object> className = ClassUtil.loadClass(metadata.getClassName());
// 排除 DataSourceAutoConfiguration 自动注入
SpringBootApplication boot = AnnotationUtil.getAnnotation(className, SpringBootApplication.class);
// 修改值
Class<?>[] exclude = boot.exclude();
if (!ArrayUtil.contains(exclude, DataSourceAutoConfiguration.class)) {
Class<? extends Object>[] excludeClass = ArrayUtil.append(exclude, DataSourceAutoConfiguration.class);
EntityUtil.putAnnotationValue(boot, "exclude", excludeClass);
}
// 获取注解值
EnableTxSeata txSeata = AnnotationUtil.getAnnotation(className, EnableTxSeata.class);
// 加载相关配置
ConfigType type = txSeata.value();
switch(type) {
case // 0.7.1 只支持nacos
Nacos:
// 整合seata-nacos
Properties properties = this.getNacosProp();
// 获取配置资源
try {
ConfigService configService = NacosFactory.createConfigService(properties);
// NacosConfiguration
EntityUtil.setPrivateFinalField(NacosConfiguration.class, "configService", configService);
//
NacosConfiguration configuration = NacosConfiguration.getInstance();
// ConfigurationFactory
EntityUtil.setPrivateFinalField(ConfigurationFactory.class, "instance", configuration);
// 修改注册-nacos
// EntityUtil.setPrivateFinalField(ConfigurationFactory.class,
// "DEFAULT_FILE_INSTANCE", configuration);
EntityUtil.setPrivateFinalField(ConfigurationFactory.class, "CURRENT_FILE_INSTANCE", configuration);
// 修改服务发现
NamingService namingService = NamingFactory.createNamingService(properties);
EntityUtil.setPrivateFinalField(NacosRegistryServiceImpl.class, "naming", namingService);
} catch (Exception e) {
log.error("{}", e);
throw new BusinessException("Nacos-Seata 初始化失败");
}
return new String[] { TxSeataConfig.class.getName() };
default:
break;
}
return null;
}
Aggregations