790477691 opened a new issue, #23516:
URL: https://github.com/apache/shardingsphere/issues/23516

   
   ### Which version of ShardingSphere did you use?
   5.3.1
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   shardingsphere-jdbc-core
   ### Expected behavior
   Normal load data source
   ### Actual behavior
   An error occurred loading the data source:
   ```text
   org.springframework.beans.factory.BeanCreationException: Error creating bean 
with name 'dataSourceAwareService': Injection of autowired dependencies failed; 
nested exception is 
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundException:
 SPI-00001: No implementation class load from SPI 
`org.apache.shardingsphere.infra.instance.metadata.InstanceMetaDataBuilder` 
with type `JDBC`.
        at 
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:380)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1411)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592)
        at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
        at 
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
        at 
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
        at 
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:845)
        at 
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
        at 
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
        at 
org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
        at 
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
        at 
org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
        at 
org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
        at 
org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:139)
        at com.hnmjm.vehicle.spring.SpringBoot.startWeb(SpringBoot.java:46)
        at com.hnmjm.vehicle.midsrv.MiddleServer.main(MiddleServer.java:53)
   Caused by: 
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundException:
 SPI-00001: No implementation class load from SPI 
`org.apache.shardingsphere.infra.instance.metadata.InstanceMetaDataBuilder` 
with type `JDBC`.
        at 
org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPIRegistry.getRegisteredService(TypedSPIRegistry.java:100)
        at 
org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.createContextManager(ShardingSphereDataSource.java:72)
        at 
org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.<init>(ShardingSphereDataSource.java:66)
        at 
org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory.createDataSource(ShardingSphereDataSourceFactory.java:93)
        at 
com.hnmjm.vehicle.db.DataSourceAwareService.setDataSourceInitAware(DataSourceAwareService.java:136)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at 
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:708)
        at 
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90)
        at 
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374)
        ... 17 more
   ```
   ### Reason analyze (If you can)
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   
   ### Example codes for reproduce this issue (such as a github link).
   ```xml
           <!-- 
https://mvnrepository.com/artifact/org.apache.shardingsphere/shardingsphere-jdbc-core
 -->
           <dependency>
               <groupId>org.apache.shardingsphere</groupId>
               <artifactId>shardingsphere-jdbc-core</artifactId>
               <version>5.3.1</version>
               <exclusions>
                   <exclusion>
                       <artifactId>shardingsphere-infra-util</artifactId>
                       <groupId>org.apache.shardingsphere</groupId>
                   </exclusion>
               </exclusions>
           </dependency>
           <!-- 
https://mvnrepository.com/artifact/org.apache.shardingsphere/shardingsphere-infra-util
 -->
           <dependency>
               <groupId>org.apache.shardingsphere</groupId>
               <artifactId>shardingsphere-infra-util</artifactId>
               <version>5.2.0</version>
           </dependency>
   ```
   ```text
   # ============= 数据源基础配置(这边配置所有数据源共享属性) =============
   # 连接池初始化大小,最小,最大
   default.initialSize=2
   default.minIdle=1
   default.maxActive=500
   # 配置获取连接等待超时的时间
   default.maxWait=60000
   # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
   default.timeBetweenEvictionRunsMillis=3000
   # 配置一个连接在池中最小生存的时间,单位是毫秒
   default.minEvictableIdleTimeMillis=300000
   default.validationQuery=SELECT 'x' FROM DUAL
   default.testWhileIdle=true
   default.testOnBorrow=false
   default.testOnReturn=false
   # 打开PSCache,并且指定每个连接上PSCache的大小
   default.poolPreparedStatements=true
   default.maxPoolPreparedStatementPerConnectionSize=20
   # 配置监控统计拦截的filters
   default.filters=stat
   # 默认数据源
   db.default=root
   # ============= 具体数据源配置(若有需要,可覆盖基础配置属性) =============
   # 数据源1
   root1.driverClassName=${root-driver:@jdbc.driverClassName1@}
   root1.url=${root-url:@jdbc.url1@}
   root1.username=${root-username:@jdbc.username1@}
   root1.password=${root-password:@jdbc.password1@}
   root1.initialSize=5
   root1.minIdle=2
   root1.maxActive=60
   
   # 数据源2
   root2.driverClassName=${root-driver:@jdbc.driverClassName2@}
   root2.url=${root-url:@jdbc.url2@}
   root2.username=${root-username:@jdbc.username2@}
   root2.password=${root-password:@jdbc.password2@}
   root2.initialSize=5
   root2.minIdle=2
   root2.maxActive=60
   # 数据源2
   root3.driverClassName=${root-driver:@jdbc.driverClassName3@}
   root3.url=${root-url:@jdbc.url3@}
   root3.username=${root-username:@jdbc.username3@}
   root3.password=${root-password:@jdbc.password3@}
   root3.initialSize=5
   root3.minIdle=2
   root3.maxActive=60
   
   # mysql数据源
   [email protected]@
   [email protected]@
   [email protected]@
   [email protected]@
   mysql.initialSize=5
   mysql.minIdle=2
   mysql.maxActive=60
   ```
   ```java
           Map<String, DataSource> dataSourceMap = new HashMap<>(); //设置分库映射
   
           for (String dataSourceName : 
dataSourceProperties.getDataSourceKeys()) {
               final Properties properties = 
DataSourceProperties.getPropertiesWithNewPrefix(dataSourceName, "druid");
               DruidDataSource dataSource = 
DataSourceProperties.getDataSourceTemplate();
               if(dataSourceName.contains("root")){
                   
dataSource.setDriverClassName(properties.getProperty("druid.driverClassName" + 
dataSourceName.substring(dataSourceName.length() - 1)));
                   dataSource.setUrl(properties.getProperty("druid.url" + 
dataSourceName.substring(dataSourceName.length() - 1)));
                   
dataSource.setUsername(properties.getProperty("druid.username" + 
dataSourceName.substring(dataSourceName.length() - 1)));
                   
dataSource.setPassword(properties.getProperty("druid.password" + 
dataSourceName.substring(dataSourceName.length() - 1)));
                   dataSource.configFromPropety(properties);
                   dataSource.init();
                   dataSourceMap.put(dataSourceName, dataSource);
               }else{
                   
dataSource.setDriverClassName(properties.getProperty("druid.driverClassName"));
                   dataSource.setUrl(properties.getProperty("druid.url"));
                   
dataSource.setUsername(properties.getProperty("druid.username"));
                   
dataSource.setPassword(properties.getProperty("druid.password"));
                   dataSource.configFromPropety(properties);
                   dataSource.init();
                   dataSourceRegistry.registerDataSource(dataSourceName, 
dataSource);
                   LOG.info("初始化基础数据源:" + dataSource.getName() + " => " + 
dataSource);
               }
           }
   
           if(dataSourceMap.size() > 0){
               //配置分片策略
               ShardingRuleConfiguration shardingRuleConfiguration = new 
ShardingRuleConfiguration();
               List<String> BroadcastTables = new ArrayList<>();
               BroadcastTables.add("MJM_REPORT_LAST_POSITION");
               BroadcastTables.add("MJM_8702");
               BroadcastTables.add("T_SERVER_DB");
               BroadcastTables.add("T_GPS_RECORD_LOG_JOB");
               BroadcastTables.add("MJM_PICTURE_MATCH");
               
shardingRuleConfiguration.getBroadcastTables().addAll(BroadcastTables);
               List<String> TableRuleConfigs = new ArrayList<>();
               TableRuleConfigs.add("MJM_GPS_RECORD");
               TableRuleConfigs.add("MJM_JS_ATTACHMENT");
               TableRuleConfigs.add("MJM_JS_BLIND_AREA");
               TableRuleConfigs.add("MJM_JS_DRIVER_STATUS");
               TableRuleConfigs.add("MJM_JS_DRIVING_ASS");
               TableRuleConfigs.add("MJM_WARNING");
   //            TableRuleConfigs.add("WARNING_COLLECT_DAY");
               for (String tableName:TableRuleConfigs) {
                   ShardingTableRuleConfiguration tableRuleConfiguration = new 
ShardingTableRuleConfiguration(tableName,"root$->{1..3}." + tableName);
                   tableRuleConfiguration.setDatabaseShardingStrategy(new 
StandardShardingStrategyConfiguration("ID","inline"));
                   tableRuleConfiguration.setTableShardingStrategy(new 
NoneShardingStrategyConfiguration());
                   
shardingRuleConfiguration.getTables().add(tableRuleConfiguration);
                   Properties props = new Properties();
                   props.setProperty("algorithm-expression", "root${ID % 3 + 
1}");
                   
shardingRuleConfiguration.getShardingAlgorithms().put("inline", new 
AlgorithmConfiguration("INLINE", props));
               }
   //            
shardingRuleConfiguration.getBindingTableGroups().addAll(TableRuleConfigs);
   
               DataSource shardingDataSource = 
ShardingSphereDataSourceFactory.createDataSource("root",new 
ModeConfiguration("Standalone",new 
StandalonePersistRepositoryConfiguration("JDBC",new 
Properties())),dataSourceMap , 
Collections.singleton(shardingRuleConfiguration), getProperties());
               dataSourceRegistry.registerDataSource("root", 
shardingDataSource);
               LOG.info("初始化ShardingSphere-JDBC基础数据源:"  + shardingDataSource);
           }
   ```
   
   


-- 
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]

Reply via email to