apache / shardingsphere

Empowering Data Intelligence with Distributed SQL for Sharding, Scalability, and Security Across All Databases.
Apache License 2.0
19.95k stars 6.74k forks source link

I encounter incompatible problems with the shardingjdbc when I use alibaba springcloud 2.2.X #7783

Closed szlzhm closed 4 years ago

szlzhm commented 4 years ago

When I use alibaba springcloud 2.2X sentinel seata feign to setup my spring cloud project, I encounter incompatible problems with the shardingjdbc.I use shardingjdbc4.1.X is also unable to solve this problem, ask for help. When remove shardingjdbc away from my project ,it doing work well.

The exception and application.properties and springboot main class and pom.xml are listed at bellow. spring boot main class : @SpringBootApplication(scanBasePackages = "com.kuangchi") @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) @EnableDiscoveryClient @EnableFeignClients

@MapperScan(basePackages = "com.kuangchi.mapper") public class SentinelApplicationpublic static void main(String[] args) throws Exception { SpringApplication.run(SentinelApplication.class, args); } } application.properties:

feign.okhttp.enabled=true

feign.sentinel.enabled=true management.endpoints.web.exposure.include=*

ribbon.okhttp.enabled=true

server.port=8088 spring.shardingsphere.datasource.names=ds0,ds1 spring.shardingsphere.datasource.ds0.driver-class-name=com.mysql.jdbc.Driver spring.shardingsphere.datasource.ds0.jdbc-url=jdbc:mysql://10.2.28.41:3306/demo_ds0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8 spring.shardingsphere.datasource.ds0.password=XXXXXXX spring.shardingsphere.datasource.ds0.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.ds0.username=root spring.shardingsphere.datasource.ds1.driver-class-name=com.mysql.jdbc.Driver spring.shardingsphere.datasource.ds1.jdbc-url=jdbc:mysql://10.2.28.41:3306/demo_ds1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8 spring.shardingsphere.datasource.ds1.password=XXXXXXX spring.shardingsphere.datasource.ds1.type=com.zaxxer.hikari.HikariDataSource spring.shardingsphere.datasource.ds1.username=root

spring.shardingsphere.props.sql-show=true spring.shardingsphere.props.sharding.binding-tables=t_order,t_order_item spring.shardingsphere.props.sharding.broadcast-tables=t_address spring.shardingsphere.props.sharding.default-database-strategy.inline.algorithm-expression=ds$->{user_id % 2} spring.shardingsphere.props.sharding.default-database-strategy.inline.sharding-column=user_id spring.shardingsphere.props.sharding.tables.t_order.actual-data-nodes=ds$->{0..1}.t_order spring.shardingsphere.props.sharding.tables.t_order.key-generator.column=order_id spring.shardingsphere.props.sharding.tables.t_order.key-generator.props.worker.id=123 spring.shardingsphere.props.sharding.tables.t_order.key-generator.type=SNOWFLAKE spring.shardingsphere.props.sharding.tables.t_order_item.actual-data-nodes=ds$->{0..1}.t_order_item spring.shardingsphere.props.sharding.tables.t_order_item.key-generator.column=order_item_id spring.shardingsphere.props.sharding.tables.t_order_item.key-generator.props.worker.id=123 spring.shardingsphere.props.sharding.tables.t_order_item.key-generator.type=SNOWFLAKE spring.application.name=badger-spring-cloud-alibaba-sentinel spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848 spring.cloud.sentinel.transport.dashboard=127.0.0.1:8080 spring.cloud.sentinel.transport.port=8719 spring.cloud.sentinel.datasource.ds1.nacos.server-addr=127.0.0.1:8848 spring.cloud.sentinel.datasource.ds1.nacos.data-id=${spring.application.name} spring.cloud.sentinel.datasource.ds1.nacos.rule-type=flow

POM.xml

org.springframework.boot spring-boot-starter-parent 2.2.1.RELEASE
<dependencies>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>22.0</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy</artifactId>
        <version>3.0.6</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>

    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
    </dependency>

    <dependency>

        <groupId>com.alibaba.csp</groupId>
        <artifactId>sentinel-datasource-nacos</artifactId>

        <exclusions>
            <exclusion>
                <groupId>com.alibaba.nacos</groupId>
                <artifactId>nacos-client</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
    </dependency>
    <dependency>
        <groupId>com.alibaba.cloud</groupId>
        <artifactId>spring-cloud-starter-alibaba-seata</artifactId>
       <exclusions>
            <exclusion>
                <artifactId>seata-all</artifactId>
                <groupId>io.seata</groupId>
            </exclusion>
        </exclusions>
    </dependency>

   <dependency>
        <groupId>io.seata</groupId>
        <artifactId>seata-spring-boot-starter</artifactId>
        <version>1.1.0</version>
    </dependency>
    <!--sharejdbc begin -->

    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-boot-starter</artifactId>
        <version>3.4.0</version>
    </dependency>

    <dependency>
        <groupId>com.zaxxer</groupId>
        <artifactId>HikariCP</artifactId>
        <version>3.4.2</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.47</version>
    </dependency>

    <dependency>
        <groupId>org.apache.shardingsphere</groupId>
        <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
        <version>4.1.1</version>
        <exclusions>
            <exclusion>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-- sharejdbc end-->

</dependencies>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-dependencies</artifactId>
            <version>2.2.1.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Hoxton.SR1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

    </dependencies>
</dependencyManagement>

Exception:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shardingDataSource' defined in class path resource [org/apache/shardingsphere/shardingjdbc/spring/boot/SpringBootConfiguration.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:603) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.addCandidateEntry(DefaultListableBeanFactory.java:1503) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1467) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveMultipleBeans(DefaultListableBeanFactory.java:1386) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1245) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:874) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:778) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] ... 116 common frames omitted Caused by: java.lang.IllegalArgumentException: null at org.objectweb.asm.ClassReader.(Unknown Source) ~[asm-4.2.jar:4.2] at org.objectweb.asm.ClassReader.(Unknown Source) ~[asm-4.2.jar:4.2] at org.objectweb.asm.ClassReader.(Unknown Source) ~[asm-4.2.jar:4.2] at net.sf.cglib.proxy.BridgeMethodResolver.resolveAll(BridgeMethodResolver.java:61) ~[cglib-3.1.jar:na] at net.sf.cglib.proxy.Enhancer.emitMethods(Enhancer.java:911) ~[cglib-3.1.jar:na] at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:498) ~[cglib-3.1.jar:na] at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25) ~[cglib-3.1.jar:na] at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216) ~[cglib-3.1.jar:na] at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377) ~[cglib-3.1.jar:na] at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285) ~[cglib-3.1.jar:na] at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:663) ~[cglib-3.1.jar:na] at io.seata.spring.annotation.datasource.SeataDataSourceBeanPostProcessor.proxyDataSource(SeataDataSourceBeanPostProcessor.java:77) ~[seata-all-1.1.0.jar:1.1.0] at io.seata.spring.annotation.datasource.SeataDataSourceBeanPostProcessor.postProcessAfterInitialization(SeataDataSourceBeanPostProcessor.java:52) ~[seata-all-1.1.0.jar:1.1.0] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:431) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1807) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:595) ~[spring-beans-5.2.1.RELEASE.jar:5.2.1.RELEASE] ... 129 common frames omitted

tristaZero commented 4 years ago

Hi @szlzhm Do you think sharding-example can give you some points?

szlzhm commented 4 years ago

Hi @szlzhm Do you think sharding-example can give you some points?

Sorry,this cant solve my problem. I am using alibaba-springcloud-seata ,not io.seata.all

tristaZero commented 4 years ago

Sorry, I am not a user of alibaba-springcloud-seata. Also, I can not get any key info from the log above. I feel more logs about the sharding sphere can give us more hints.

kimmking commented 4 years ago

@szlzhm I guess this is an alibaba-springcloud-seata issue.