shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

Has error when use orchestration and mybatis-plus with springboot

Open yl1935 opened this issue 6 years ago • 1 comments

Bug Report

Project: Shading-JDBC Verson:4.0.0

I works well on local sharding config with mybatis-plus, and I think it will works well too on orchestration config with registry, but it won't. The error message is "Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured."

The springboot version is 2.2.4 and I use mybatis-plus and sharding-jdbc-orchestration-spring-boot-starter

    <dependency>
        <groupId>com.baomidou</groupId>
        <artifactId>mybatis-plus-boot-starter</artifactId>
        <version>3.3.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.shardingsphere</groupId>
        <artifactId>sharding-transaction-xa-core</artifactId>
        <version>4.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.shardingsphere</groupId>
        <artifactId>sharding-jdbc-orchestration-spring-boot-starter</artifactId>
        <version>4.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.shardingsphere</groupId>
        <artifactId>sharding-orchestration-reg-zookeeper-curator</artifactId>
        <version>4.0.0</version>
    </dependency>

I have read the source code and compared org.apache.shardingsphere.shardingjdbc.spring.boot.SpringBootConfiguration.java(works well) with org.apache.shardingsphere.shardingjdbc.orchestration.spring.boot.OrchestrationSpringBootConfiguration.java (can not work, throws error when startup project)

I found @AutoConfigureBefore(DataSourceAutoConfiguration.class) is missing in OrchestrationSpringBootConfiguration.java, I think this is the real reason, I try to add @AutoConfigureBefore in OrchestrationSpringBootConfiguration.java and repackage and replace the local sharding-jdbc-orchestration-spring-boot-starter.jar with the jar I modified, then the error has gone. Because mybatis-plus include spring-boot-starter-jdbc.jar, I think its DataSourceAutoConfiguration loads config before OrchestrationSpringBootConfiguration so the error happened.

yl1935 avatar Feb 11 '20 02:02 yl1935

@yl1935 Thanks for your feedback, would you like to submit a pull request to fix this bug? it is a good opportunity to get involved.

yanyzy avatar Feb 26 '20 02:02 yanyzy