apache / shardingsphere

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

How to configure shardingsphere jdbc 5.3.1 Using springMVC Namespace #23543

Closed 790477691 closed 1 year ago

790477691 commented 1 year ago

shardingsphere jdbc 5.3.1 How to use springMVC namespace configuration, no configuration example

Pace2Car commented 1 year ago

Refer to: https://shardingsphere.apache.org/document/current/en/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/spring-namespace/

790477691 commented 1 year ago
org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:h2:mem:config;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
    at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:305)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:378)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:474)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:289)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:47)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
    at com.sun.proxy.$Proxy93.queryPageDayTrajectory(Unknown Source)
    at com.uzhie.web.service.GpsService.trajectoryTexts_1(GpsService.java:1629)
    at com.uzhie.web.service.GpsService.access$300(GpsService.java:58)
    at com.uzhie.web.service.GpsService$4.call(GpsService.java:1542)
    at com.uzhie.web.service.GpsService$4.call(GpsService.java:1508)
    at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
    at java.util.concurrent.FutureTask.run(FutureTask.java)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:h2:mem:config;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
    at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:114)
    at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:321)
    at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:110)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:108)
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
    at org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepository.init(JDBCRepository.java:67)
    at org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry.getRegisteredService(RequiredSPIRegistry.java:45)
    at org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepositoryFactory.getInstance(StandalonePersistRepositoryFactory.java:44)
    at org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder.build(StandaloneContextManagerBuilder.java:44)
    at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.createContextManager(ShardingSphereDataSource.java:76)
    at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.<init>(ShardingSphereDataSource.java:64)
    at org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory.createDataSource(ShardingSphereDataSourceFactory.java:93)
    at org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:133)
    at org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:75)
    at org.apache.shardingsphere.driver.jdbc.core.driver.DriverDataSourceCache.createDataSource(DriverDataSourceCache.java:51)
    at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
    at org.apache.shardingsphere.driver.jdbc.core.driver.DriverDataSourceCache.get(DriverDataSourceCache.java:45)
    at org.apache.shardingsphere.driver.ShardingSphereDriver.connect(ShardingSphereDriver.java:51)
    at org.springframework.jdbc.datasource.SimpleDriverDataSource.getConnectionFromDriver(SimpleDriverDataSource.java:143)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:205)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:169)
    at org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource.getConnection(AbstractRoutingDataSource.java:169)
    at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:262)
    ... 20 more
Caused by: java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getDriver(DriverManager.java:315)
    at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:106)
    ... 42 more
        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>shardingsphere-jdbc-core</artifactId>
            <version>5.2.1</version>
        </dependency>
databaseName: oracleSource

dataSources:
  oracleSource1:
    dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
    driverClassName: oracle.jdbc.driver.OracleDriver
    jdbcUrl: jdbc:oracle:thin:@//111.111.11.13:9521/road
    username: road
    password: road
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
  oracleSource2:
    dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
    driverClassName: oracle.jdbc.driver.OracleDriver
    jdbcUrl: jdbc:oracle:thin:@//111.111.11.12:9521/road1
    username: road1
    password: road1
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
  oracleSource3:
    dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
    driverClassName: oracle.jdbc.driver.OracleDriver
    jdbcUrl: jdbc:oracle:thin:@//111.111.11.11:9521/road2
    username: road2
    password: road2
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1

rules:
  - !SHARDING
    tables:
      MJM_GPS_RECORD:
        actualDataNodes: oracleSource${1..3}.MJM_GPS_RECORD
        databaseStrategy:
          standard:
            shardingColumn: TELEPHONE
            shardingAlgorithmName: hint_test
      MJM_JS_ATTACHMENT:
        actualDataNodes: oracleSource${1..3}.MJM_JS_ATTACHMENT
        databaseStrategy:
          standard:
            shardingColumn: SIM_NUMBER
            shardingAlgorithmName: hint_test
      MJM_JS_BLIND_AREA:
        actualDataNodes: oracleSource${1..3}.MJM_JS_BLIND_AREA
        databaseStrategy:
          standard:
            shardingColumn: SIM_NUMBER
            shardingAlgorithmName: hint_test
      MJM_JS_DRIVER_STATUS:
        actualDataNodes: oracleSource${1..3}.MJM_JS_DRIVER_STATUS
        databaseStrategy:
          standard:
            shardingColumn: SIM_NUMBER
            shardingAlgorithmName: hint_test
      MJM_JS_DRIVING_ASS:
        actualDataNodes: oracleSource${1..3}.MJM_JS_DRIVING_ASS
        databaseStrategy:
          standard:
            shardingColumn: SIM_NUMBER
            shardingAlgorithmName: hint_test
      MJM_WARNING:
        actualDataNodes: oracleSource${1..3}.MJM_WARNING
        databaseStrategy:
          standard:
            shardingColumn: SIM_NUMBER
            shardingAlgorithmName: hint_test
    bindingTables:
      - MJM_GPS_RECORD,MJM_JS_ATTACHMENT,MJM_JS_BLIND_AREA,MJM_JS_DRIVER_STATUS,MJM_JS_DRIVING_ASS,MJM_WARNING
    broadcastTables:
      - MJM_REPORT_LAST_POSITION,MJM_8702,T_SERVER_DB,T_GPS_RECORD_LOG_JOB,MJM_PICTURE_MATCH

#    defaultDatabaseStrategy:
#      hint:
#        shardingColumn:
#        shardingAlgorithmName: hint_test
#    defaultTableStrategy:
#      none:

    shardingAlgorithms:
      hint_test:
        type: HINT_TEST
props:
  max-connections-size-per-query: 1
  kernel-executor-size: 16  # Infinite by default.
  proxy-frontend-flush-threshold: 128  # The default value is 128.
  proxy-hint-enabled: true
  sql-show: true
  check-table-metadata-enabled: false
    <bean id="dataSource" class="com.uzhie.dataSoruce.DynamicDataSource">
        <property name="targetDataSources">
            <map>
                <entry key="mysqlSource" value-ref="mysqlSource"/>
                <entry key="mysqlSourceBj" value-ref="mysqlSourceBj"/>
                <entry key="oracleSource" value-ref="oracleSource"/>
<!--                <entry key="oracleSource" value-ref="shardingDataSource"/>-->
<!--                <entry key="h2Source" value-ref="h2Source" />-->
            </map>
        </property>
        <property name="defaultTargetDataSource" ref="mysqlSource"/>
    </bean>

    <bean id="oracleSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
        <property name="driverClass" value="org.apache.shardingsphere.driver.ShardingSphereDriver"/>
        <property name="url" value="jdbc:shardingsphere:classpath:scratch.yml" />
    </bean>

An error occurred using this configuration

790477691 commented 1 year ago
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                      http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.uzhie</groupId>
    <artifactId>mjm-web-server</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>

    <properties>
        <!-- junit 版本号 -->
        <junit.version>4.12</junit.version>
        <!-- log4j日志文件管理包版本 -->
        <slf4j.version>1.7.7</slf4j.version>
        <log4j.version>1.2.17</log4j.version>
        <spring.version>5.0.4.RELEASE</spring.version>
        <spring.data.version>2.0.0.RELEASE</spring.data.version>
        <fasterxml.jackson>2.9.0</fasterxml.jackson>
        <!-- redis 版本 -->
        <redis.version>2.9.0</redis.version>
        <kafka.version>2.0.0</kafka.version>
        <spring-kafka.version>2.2.0.RELEASE</spring-kafka.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <repositories>
        <repository>
            <id>central</id>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
            <layout>default</layout>
            <!-- 是否开启发布版构件下载 -->
            <releases>
                <enabled>true</enabled>
            </releases>
            <!-- 是否开启快照版构件下载 -->
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
</repositories>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/com.oracle.jdbc/com.springsource.oracle.jdbc -->
<!--        <dependency>-->
<!--            <groupId>com.oracle.jdbc</groupId>-->
<!--            <artifactId>com.springsource.oracle.jdbc</artifactId>-->
<!--            <version>10.2.0.2</version>-->
<!--            <systemPath>${project.basedir}/lib/taobao-sdk-java-auto_1479188381469-20190628.jar</systemPath>-->
<!--        </dependency>-->
        <!-- https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8 -->
        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc8</artifactId>
            <version>12.2.0.1</version>
        </dependency>

        <dependency>
            <groupId>com.oracle.database.nls</groupId>
            <artifactId>orai18n</artifactId>
            <version>11.2.0.4</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.shardingsphere/shardingsphere-jdbc-core -->
        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>shardingsphere-jdbc-core</artifactId>
            <version>5.2.1</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>4.4.1</version>
        </dependency>
        <!-- mp 依赖 -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus</artifactId>
            <version>2.3</version>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>cn.easyproject</groupId>-->
<!--            <artifactId>ojdbc6</artifactId>-->
<!--            <version>12.1.0.2.0</version>-->
<!--        </dependency>-->
        <!-- https://mvnrepository.com/artifact/org.freemarker/freemarker -->
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.23</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty-all</artifactId>
            <version>4.1.42.Final</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${slf4j.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.8.9</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.32</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-websocket</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-messaging</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${fasterxml.jackson}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${fasterxml.jackson}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>${fasterxml.jackson}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.20</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.3.0</version>
        </dependency>
        <!-- mybatis核心包 -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.1</version>
        </dependency>
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper</artifactId>
            <version>3.3.9</version>
        </dependency>
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.1.10</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.35</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>${spring.data.version}</version>
        </dependency>
        <dependency>
            <groupId>org.ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>3.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis.caches</groupId>
            <artifactId>mybatis-ehcache</artifactId>
            <version>1.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>25.1-jre</version>
        </dependency>
        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>2.0.1.Final</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.alibaba/easyexcel -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>2.1.4</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>5.4.2.Final</version>
        </dependency>
        <dependency>
            <groupId>javax.el</groupId>
            <artifactId>javax.el-api</artifactId>
            <version>2.2.4</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish.web</groupId>
            <artifactId>javax.el</artifactId>
            <version>2.2.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.mina</groupId>
            <artifactId>mina-core</artifactId>
            <version>2.0.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.activemq</groupId>
            <artifactId>activemq-spring</artifactId>
            <version>5.14.3</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>commons-pool</groupId>
            <artifactId>commons-pool</artifactId>
            <version>1.6</version>
        </dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>${redis.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
            <version>${spring.data.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.jms</groupId>
            <artifactId>javax.jms-api</artifactId>
            <version>2.0.1</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-api</artifactId>
            <version>0.10.5</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-impl</artifactId>
            <version>0.10.5</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt-jackson</artifactId>
            <version>0.10.5</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.6</version>
        </dependency>
        <!-- 构建Restful API -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
        </dependency>
        <!-- xxl-job-core -->
        <dependency>
            <groupId>com.xuxueli</groupId>
            <artifactId>xxl-job-core</artifactId>
            <version>2.1.0</version>
        </dependency>
        <!-- commons-lang3 -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>

        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
            <scope>provided</scope>
        </dependency>
        <!--kafka-->
        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka_2.12</artifactId>
            <version>${kafka.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
                <!--                <exclusion>-->
                <!--                    <artifactId>jmxri</artifactId>-->
                <!--                    <groupId>com.sun.jmx</groupId>-->
                <!--                </exclusion>-->
                <!--                <exclusion>-->
                <!--                    <artifactId>jms</artifactId>-->
                <!--                    <groupId>javax.jms</groupId>-->
                <!--                </exclusion>-->
                <!--                <exclusion>-->
                <!--                    <artifactId>jmxtools</artifactId>-->
                <!--                    <groupId>com.sun.jdmk</groupId>-->
                <!--                </exclusion>-->
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.apache.kafka</groupId>
            <artifactId>kafka-clients</artifactId>
            <version>${kafka.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
            <version>${spring-kafka.version}</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <version>2.5.3</version>
            <exclusions>
                <exclusion>
                    <artifactId>spring</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>com.101tec</groupId>
            <artifactId>zkclient</artifactId>
            <version>0.10</version>
        </dependency>
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.0.1</version>
        </dependency>

        <dependency>
            <groupId>commons-net</groupId>
            <artifactId>commons-net</artifactId>
            <version>3.6</version>
        </dependency>

        <!--easypoi依赖-->
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-base</artifactId>
            <version>4.1.3</version>
        </dependency>
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-web</artifactId>
            <version>4.1.3</version>
        </dependency>
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-annotation</artifactId>
            <version>4.1.3</version>
        </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.13.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-clean-plugin</artifactId>
            <version>3.1.0</version>
        </dependency>

        <!--Lombok-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.16.18</version>
            <scope>provided</scope>
        </dependency>

        <!--smb访问远程共享文件夹-->
        <dependency>
            <groupId>org.samba.jcifs</groupId>
            <artifactId>jcifs</artifactId>
            <version>1.3.14-kohsuke-1</version>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.197</version>
        </dependency>

        <!-- apache ignite缓存-->
   <!--     <dependency>
            <groupId>org.apache.ignite</groupId>
            <artifactId>ignite-core</artifactId>
            <version>${ignite.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ignite</groupId>
            <artifactId>ignite-spring</artifactId>
            <version>${ignite.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ignite</groupId>
            <artifactId>ignite-indexing</artifactId>
            <version>${ignite.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>com.h2database</groupId>
                    <artifactId>h2</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.197</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ignite</groupId>
            <artifactId>ignite-rest-http</artifactId>
            <version>${ignite.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.ignite</groupId>
            <artifactId>ignite-spring-data</artifactId>
            <version>${ignite.version}</version>
        </dependency>-->
    </dependencies>

    <profiles>
        <profile>
            <!-- 本地局域网配置文件 -->
            <id>local</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <filters>
                    <filter>
                        src/main/resource/local/log4j.properties
                    </filter>
                    <filter>
                        src/main/resource/local/db.properties
                    </filter>
                    <filter>
                        src/main/resource/local/redis.properties
                    </filter>
                    <filter>
                        src/main/resource/local/sys.properties
                    </filter>
                </filters>
            </build>
        </profile>
        <profile>
            <!-- 阿里云配置文件 -->
            <id>zz</id>
            <build>
                <filters>
                    <filter>
                        src/main/resource/zz/log4j.properties
                    </filter>
                    <filter>
                        src/main/resource/zz/db.properties
                    </filter>
                    <filter>
                        src/main/resource/zz/redis.properties
                    </filter>
                    <filter>
                        src/main/resource/zz/sys.properties
                    </filter>
                </filters>
            </build>
        </profile>
        <profile>
            <!-- MJM配置文件 -->
            <id>mjm</id>
            <build>
                <filters>
                    <filter>
                        src/main/resource/mjm/log4j.properties
                    </filter>
                    <filter>
                        src/main/resource/mjm/db.properties
                    </filter>
                    <filter>
                        src/main/resource/mjm/redis.properties
                    </filter>
                    <filter>
                        src/main/resource/mjm/sys.properties
                    </filter>
                </filters>
            </build>
        </profile>
        <profile>
            <id>temp</id>
            <!--<activation>-->
            <!--<activeByDefault>true</activeByDefault>-->
            <!--</activation>-->
            <build>
                <filters>
                    <filter>
                        src/main/resource/temp/log4j.properties
                    </filter>
                    <filter>
                        src/main/resource/temp/db.properties
                    </filter>
                    <filter>
                        src/main/resource/temp/redis.properties
                    </filter>
                    <filter>
                        src/main/resource/temp/sys.properties
                    </filter>
                </filters>
            </build>
        </profile>
    </profiles>

    <build>
        <finalName>mjm-web-server</finalName>
        <resources>
            <resource>
                <directory>src/main/resource</directory>
                <includes>
                    <include>**/*</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resource</directory>
                <includes>
                    <include>log4j.properties</include>
                    <include>db.properties</include>
                    <include>redis.properties</include>
                    <include>sys.properties</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>

        <plugins>
            <!-- jdk版本1.8 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>utf-8</encoding>
                </configuration>
            </plugin>

            <!--打包跳过测试类-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                    <skip>true</skip>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-installed</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>${project.groupId}</groupId>
                                    <artifactId>${project.artifactId}</artifactId>
                                    <version>${project.version}</version>
                                    <type>${project.packaging}</type>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>target/lib</outputDirectory>
                        </configuration>
                    </execution>
                    <execution>
                        <id>copy-lib</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                            <includeScope>compile</includeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
RaigorJiang commented 1 year ago
Caused by: java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:h2:mem:config;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
    at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:114)
    at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:321)
    at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:110)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:108)
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
    at org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepository.init(JDBCRepository.java:67)
    at org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry.getRegisteredService(RequiredSPIRegistry.java:45)
    at org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepositoryFactory.getInstance(StandalonePersistRepositoryFactory.java:44)
    at org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder.build(StandaloneContextManagerBuilder.java:44)
    at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.createContextManager(ShardingSphereDataSource.java:76)
    at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.<init>(ShardingSphereDataSource.java:64)
    at org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory.createDataSource(ShardingSphereDataSourceFactory.java:93)
    at org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:133)
    at org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:75)
    at org.apache.shardingsphere.driver.jdbc.core.driver.DriverDataSourceCache.createDataSource(DriverDataSourceCache.java:51)
    at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
    at org.apache.shardingsphere.driver.jdbc.core.driver.DriverDataSourceCache.get(DriverDataSourceCache.java:45)
    at org.apache.shardingsphere.driver.ShardingSphereDriver.connect(ShardingSphereDriver.java:51)
    at org.springframework.jdbc.datasource.SimpleDriverDataSource.getConnectionFromDriver(SimpleDriverDataSource.java:143)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:205)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:169)
    at org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource.getConnection(AbstractRoutingDataSource.java:169)
    at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:262)
    ... 20 more
Caused by: java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getDriver(DriverManager.java:315)
    at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:106)
    ... 42 more

Looks like the driver for H2 is missing, please try to add it to your pom:

<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <version>2.1.214</version>
</dependency>
790477691 commented 1 year ago

@RaigorJiang But I'm using an oracle driver

    <bean id="oracleSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
        <property name="driverClass" value="org.apache.shardingsphere.driver.ShardingSphereDriver"/>
        <property name="url" value="jdbc:shardingsphere:classpath:scratch.yml" />
    </bean>
databaseName: oracleSource

dataSources:
  oracleSource1:
    dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
    driverClassName: oracle.jdbc.driver.OracleDriver
    jdbcUrl: jdbc:oracle:thin:@111.111.111.11:9521:road
    username: road
    password: road
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
  oracleSource2:
    dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
    driverClassName: oracle.jdbc.driver.OracleDriver
    jdbcUrl: jdbc:oracle:thin:@111.111.111.11:9521:road1
    username: road1
    password: road1
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1
  oracleSource3:
    dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
    driverClassName: oracle.jdbc.driver.OracleDriver
    jdbcUrl: jdbc:oracle:thin:@111.111.111.11:9521:road2
    username: road2
    password: road2
    connectionTimeoutMilliseconds: 30000
    idleTimeoutMilliseconds: 60000
    maxLifetimeMilliseconds: 1800000
    maxPoolSize: 50
    minPoolSize: 1

rules:
  - !SHARDING
    tables:
      MJM_GPS_RECORD:
        actualDataNodes: oracleSource${1..3}.MJM_GPS_RECORD
        databaseStrategy:
          standard:
            shardingColumn: TELEPHONE
            shardingAlgorithmName: hint_test
      MJM_JS_ATTACHMENT:
        actualDataNodes: oracleSource${1..3}.MJM_JS_ATTACHMENT
        databaseStrategy:
          standard:
            shardingColumn: SIM_NUMBER
            shardingAlgorithmName: hint_test
      MJM_JS_BLIND_AREA:
        actualDataNodes: oracleSource${1..3}.MJM_JS_BLIND_AREA
        databaseStrategy:
          standard:
            shardingColumn: SIM_NUMBER
            shardingAlgorithmName: hint_test
      MJM_JS_DRIVER_STATUS:
        actualDataNodes: oracleSource${1..3}.MJM_JS_DRIVER_STATUS
        databaseStrategy:
          standard:
            shardingColumn: SIM_NUMBER
            shardingAlgorithmName: hint_test
      MJM_JS_DRIVING_ASS:
        actualDataNodes: oracleSource${1..3}.MJM_JS_DRIVING_ASS
        databaseStrategy:
          standard:
            shardingColumn: SIM_NUMBER
            shardingAlgorithmName: hint_test
      MJM_WARNING:
        actualDataNodes: oracleSource${1..3}.MJM_WARNING
        databaseStrategy:
          standard:
            shardingColumn: SIM_NUMBER
            shardingAlgorithmName: hint_test
    bindingTables:
      - MJM_GPS_RECORD,MJM_JS_ATTACHMENT,MJM_JS_BLIND_AREA,MJM_JS_DRIVER_STATUS,MJM_JS_DRIVING_ASS,MJM_WARNING
    broadcastTables:
      - MJM_REPORT_LAST_POSITION,MJM_8702,T_SERVER_DB,T_GPS_RECORD_LOG_JOB,MJM_PICTURE_MATCH

#    defaultDatabaseStrategy:
#      hint:
#        shardingColumn:
#        shardingAlgorithmName: hint_test
#    defaultTableStrategy:
#      none:

    shardingAlgorithms:
      hint_test:
        type: HINT_TEST
props:
  max-connections-size-per-query: 1
  kernel-executor-size: 16  # Infinite by default.
  proxy-frontend-flush-threshold: 128  # The default value is 128.
  proxy-hint-enabled: true
  sql-show: true
  check-table-metadata-enabled: false
790477691 commented 1 year ago
<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <version>2.1.214</version>
</dependency>

Error message after the configuration is added:

org.springframework.transaction.CannotCreateTransactionException: Could not open JDBC Connection for transaction; nested exception is java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:h2:mem:config;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
    at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:305)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:378)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:474)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:289)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:47)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
    at com.sun.proxy.$Proxy93.queryPageDayTrajectory(Unknown Source)
    at com.uzhie.web.service.GpsService.trajectoryTexts_1(GpsService.java:1629)
    at com.uzhie.web.service.GpsService.access$300(GpsService.java:58)
    at com.uzhie.web.service.GpsService$4.call(GpsService.java:1542)
    at com.uzhie.web.service.GpsService$4.call(GpsService.java:1508)
    at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
    at java.util.concurrent.FutureTask.run(FutureTask.java)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.RuntimeException: Failed to get driver instance for jdbcUrl=jdbc:h2:mem:config;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL
    at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:114)
    at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:321)
    at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:110)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:108)
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
    at org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepository.init(JDBCRepository.java:67)
    at org.apache.shardingsphere.infra.util.spi.type.required.RequiredSPIRegistry.getRegisteredService(RequiredSPIRegistry.java:45)
    at org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepositoryFactory.getInstance(StandalonePersistRepositoryFactory.java:44)
    at org.apache.shardingsphere.mode.manager.standalone.StandaloneContextManagerBuilder.build(StandaloneContextManagerBuilder.java:44)
    at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.createContextManager(ShardingSphereDataSource.java:76)
    at org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource.<init>(ShardingSphereDataSource.java:64)
    at org.apache.shardingsphere.driver.api.ShardingSphereDataSourceFactory.createDataSource(ShardingSphereDataSourceFactory.java:93)
    at org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:133)
    at org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory.createDataSource(YamlShardingSphereDataSourceFactory.java:75)
    at org.apache.shardingsphere.driver.jdbc.core.driver.DriverDataSourceCache.createDataSource(DriverDataSourceCache.java:51)
    at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660)
    at org.apache.shardingsphere.driver.jdbc.core.driver.DriverDataSourceCache.get(DriverDataSourceCache.java:45)
    at org.apache.shardingsphere.driver.ShardingSphereDriver.connect(ShardingSphereDriver.java:51)
    at org.springframework.jdbc.datasource.SimpleDriverDataSource.getConnectionFromDriver(SimpleDriverDataSource.java:143)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:205)
    at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:169)
    at org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource.getConnection(AbstractRoutingDataSource.java:169)
    at org.springframework.jdbc.datasource.DataSourceTransactionManager.doBegin(DataSourceTransactionManager.java:262)
    ... 20 more
Caused by: java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getDriver(DriverManager.java:315)
    at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:106)
    ... 42 more
zhaojinchao95 commented 1 year ago

@790477691 Can you provider a demo project?