linhongzhi123 commented on issue #28450:
URL:
https://github.com/apache/shardingsphere/issues/28450#issuecomment-1722689871
> 您能提供一个演示来帮助重现此异常吗?
After investigation, the reason is that I used Dynamic. During the
configuration, the data source with vague encryption was handed over to Dynamic
to manage, and the problem occurred when I read yml. My Dynamic configuration
is as follows:
@Configuration
@AutoConfigureAfter({DynamicDataSourceAutoConfiguration.class,
SpringBootConfiguration.class})
public class DataSourceConfig {
public static final String SHARDING_DATA_SOURCE_NAME = "shareen";
/**
* 动态数据源配置项
*/
@Resource
private DynamicDataSourceProperties dynamicDataSourceProperties;
/**
* shardingjdbc有四种数据源,需要根据业务注入不同的数据源
*
* <p>1. 未使用分片, 脱敏的名称(默认): shardingDataSource;
* <p>2. 主从数据源: masterSlaveDataSource;
* <p>3. 脱敏数据源:encryptDataSource;
* <p>4. 影子数据源:shadowDataSource
* <p>
* shardingjdbc默认就是shardingDataSource
* 如果需要设置其他的可以使用
*
* @Resource(value="") 设置
*/
@Lazy
@Resource
DataSource shardingDataSource;
/**
* 将shardingDataSource放到了多数据源(dataSourceMap)中
* 注意有个版本的bug,3.1.1版本 不会进入loadDataSources 方法,这样就一直造成数据源注册失败
*/
@Bean
public DynamicDataSourceProvider dynamicDataSourceProvider() {
Map<String, DataSourceProperty> datasourceMap =
dynamicDataSourceProperties.getDatasource();
return new AbstractDataSourceProvider() {
@SneakyThrows
@Override
public Map<String, DataSource> loadDataSources() {
File file = new File("src/main/resources/sharding.yml");
DataSource dataSource =
YamlShardingSphereDataSourceFactory.createDataSource(file);
Map<String, DataSource> dataSourceMap =
createDataSourceMap(datasourceMap);
// 将 shardingjdbc 管理的数据源也交给动态数据源管理
dataSourceMap.put(SHARDING_DATA_SOURCE_NAME, dataSource);
return dataSourceMap;
}
};
}
/**
* 将动态数据源设置为首选的
* 当spring存在多个数据源时, 自动注入的是首选的对象
* 设置为主要的数据源之后,就可以支持shardingjdbc原生的配置方式了
*
* @return
*/
@Primary
@Bean
public DataSource dataSource(DynamicDataSourceProvider
dynamicDataSourceProvider) {
DynamicRoutingDataSource dataSource = new DynamicRoutingDataSource();
dataSource.setPrimary(dynamicDataSourceProperties.getPrimary());
dataSource.setStrict(dynamicDataSourceProperties.getStrict());
dataSource.setStrategy(dynamicDataSourceProperties.getStrategy());
dataSource.setProvider(dynamicDataSourceProvider);
dataSource.setP6spy(dynamicDataSourceProperties.getP6spy());
dataSource.setSeata(dynamicDataSourceProperties.getSeata());
return dataSource;
}
-----------------------------
DataSource dataSource =
YamlShardingSphereDataSourceFactory.createDataSource(file);
//There was a problem reading yml here
However, neither encryption nor blurring will work if I do not configure it
this way, which is OK in version 5.3.2. If I want to use shardingSphere with
Dynamic in version 5.4.0, how should I configure it? Please give me some
guidance
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]