You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "StrugglingStudentOfZZ (via GitHub)" <gi...@apache.org> on 2023/02/09 08:58:08 UTC

[GitHub] [shardingsphere] StrugglingStudentOfZZ opened a new issue, #24076: :Repeat the question but can`t resolve.[ NoSuchMethodError: com.google.common.base.Preconditions.checkNotNull(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;]

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

   **Exception**
   
   Exception occur when sping context runing and the function of  table sharding is used by sharding sphere
   
   org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shardingDataSource': Cannot resolve reference to bean 'shardingRule' while setting constructor argument with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shardingRule': Cannot resolve reference to bean 'groupLotRelationTableAlgorithm' while setting bean property 'shardingAlgorithms' with key [groupLotRelationTableAlgorithm]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'groupLotRelationTableAlgorithm': FactoryBean threw exception on object creation; nested exception is java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkNotNull(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
       at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
       ...
   Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shardingRule': Cannot resolve reference to bean 'groupLotRelationTableAlgorithm' while setting bean property 'shardingAlgorithms' with key [groupLotRelationTableAlgorithm]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'groupLotRelationTableAlgorithm': FactoryBean threw exception on object creation; nested exception is java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkNotNull(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
       at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:359) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      ...
   Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'groupLotRelationTableAlgorithm': FactoryBean threw exception on object creation; nested exception is java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkNotNull(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
       at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
      ...
   Caused by: _java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkNotNull(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
       at_ org.apache.shardingsphere.sharding.algorithm.sharding.classbased.ClassBasedShardingAlgorithm.getStrategy(ClassBasedShardingAlgorithm.java:66) ~[shardingsphere-sharding-core-5.1.2.jar:5.1.2]
       ...
   
   **base environment**
   Spring 4.3.7 + Sharding JDBC 5.1.2 + druid + hibernate
   
   ```
      <shardingsphere.version>5.1.2</shardingsphere.version>
       <guava.version>21.0</guava.version>
   ```
   
   **shardingsphere xml confing**
   
       <!-- 配置ShardingSphereDataSource -->
       <shardingsphere:data-source id="shardingDataSource" data-source-names="idcmDataSource" rule-refs="shardingRule" >
           <props>
               <prop key="sql-show">false</prop>
           </props>
       </shardingsphere:data-source>
   
       <!-- 配置sharding策略 -->
       <sharding:rule id="shardingRule">
           <sharding:table-rules>
               <sharding:table-rule logic-table="tab_trace_record"
                                    actual-data-nodes="idcmDataSource.tab_trace_record_$->{2023..2033}$->{01..12}"
                                    table-strategy-ref="tableShardingStrategy"/>
           </sharding:table-rules>
       </sharding:rule>
   
       <!-- 事务关系表路由规则-->
       <sharding:standard-strategy id="tableShardingStrategy" sharding-column="trace_start_time" algorithm-ref="groupLotRelationTableAlgorithm"/>
   
       <!--分表策略-->
       <sharding:sharding-algorithm id="groupLotRelationTableAlgorithm" type="CLASS_BASED">
           <props>
               <prop key="strategy">standard</prop>
               <prop key="algorithmClassName">com.*.*.config.sharding.TraceRecordLotRelationTableAlgorithm</prop>
           </props>
       </sharding:sharding-algorithm>
       <context:property-placeholder ignore-unresolvable="true"/>
   
       <bean id="idcmDataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
           <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
           <property name="url" value="${db.url}"/>
           <property name="username" value="${db.username}"/>
           <property name="password" value="${db.password}"/>
       </bean>
       <bean id="mySessionFactory" class="ctd.persistence.support.hibernate.MyLocalSessionFactoryBean">
           <property name="dataSource" ref="shardingDataSource"/>
           </property>
       </bean>
   
   **groupLotRelationTableAlgorithm**
     ```@Component
   public class TraceRecordLotRelationTableAlgorithm implements StandardShardingAlgorithm<Timestamp> {
   
       public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyyMM");
   
       @Override
       public String doSharding(Collection<String> collection, PreciseShardingValue<Timestamp> preciseShardingValue) {
           String logicTableName = preciseShardingValue.getLogicTableName();
           Timestamp value = preciseShardingValue.getValue();
           String targetTable = logicTableName.concat("_").concat(DATE_FORMAT.format(value.getTime()));
           if (collection.contains(targetTable)) {
               return targetTable;
           }
           throw new UnsupportedOperationException("无效的表名称: " + targetTable);
       }
   
       @Override
       public Collection<String> doSharding(Collection<String> collection, RangeShardingValue<Timestamp> rangeShardingValue) {
           Collection<String> collect = new ArrayList<>();
           Range<Timestamp> valueRange = rangeShardingValue.getValueRange();
           String between = rangeShardingValue.getLogicTableName() + "_" + DATE_FORMAT.format(valueRange.lowerEndpoint().getTime());
           String and = rangeShardingValue.getLogicTableName() + "_" + DATE_FORMAT.format(valueRange.upperEndpoint().getTime());
           for (String each : collection) {
               if (between.equals(each) || and.equals(each)) {
                   collect.add(each);
               }
           }
           return collect;
       }
   
       @Override
       public String getType() {
           return "MONTH_SHARD";
       }
   
       @Override
       public Properties getProps() {
           return null;
       }
   
       @Override
       public void init(Properties properties) {
           System.out.println("init");
       }
   }
   ```
   
   
   **In order to resovle to exception, many other issues that alike the exception have been browse by me and the most suggestion which transform the version of guava (such as 21.0/27.1-jre/29.1-jre/29.0-jre/18.0) is invalid.**
   
   _**Additional**_
   
   the Alternate version of sharing sphere jdbc have verified in my base enviroment and occur different exception.
   
   1.       <shardingsphere.version>5.1.0</shardingsphere.version>
           <guava.version>21.0</guava.version>
   
    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'groupLotRelationTableAlgorithm': FactoryBean threw exception on object creation; nested exception is java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkNotNull(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;
   
   like 5.1.2
   
   2.     <shardingsphere.version>5.0.0</shardingsphere.version>
           <guava.version>21.0</guava.version>
   
   org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shardingDataSource': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
   
   like other issue
   
   3.         <shardingsphere.version>5.0.0-alpha</shardingsphere.version>
           <guava.version>21.0</guava.version>
   
   org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in class path resource [spring-sharding.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V
   
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] TeslaCN commented on issue #24076: :Repeat the question but can`t resolve.[ NoSuchMethodError: com.google.common.base.Preconditions.checkNotNull(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;]

Posted by "TeslaCN (via GitHub)" <gi...@apache.org>.
TeslaCN commented on issue #24076:
URL: https://github.com/apache/shardingsphere/issues/24076#issuecomment-1425027908

   Please try upgrading the guava and check the classpath to make sure the upgrade worked.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] StrugglingStudentOfZZ closed issue #24076: :Repeat the question but can`t resolve.[ NoSuchMethodError: com.google.common.base.Preconditions.checkNotNull(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;]

Posted by "StrugglingStudentOfZZ (via GitHub)" <gi...@apache.org>.
StrugglingStudentOfZZ closed issue #24076: :Repeat the question but can`t resolve.[ NoSuchMethodError: com.google.common.base.Preconditions.checkNotNull(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;]
URL: https://github.com/apache/shardingsphere/issues/24076


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] StrugglingStudentOfZZ commented on issue #24076: :Repeat the question but can`t resolve.[ NoSuchMethodError: com.google.common.base.Preconditions.checkNotNull(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object;]

Posted by "StrugglingStudentOfZZ (via GitHub)" <gi...@apache.org>.
StrugglingStudentOfZZ commented on issue #24076:
URL: https://github.com/apache/shardingsphere/issues/24076#issuecomment-1427045102

   Thanks for your reminding. In my project, with another jar which owns different name and identical content  that equal the low version of guava , it have exclued by me and I clear the cache. in the end, the  issue is resolved.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org