sharding-jdbc-spring-boot-starter 整合 mybatis-plus-boot-starter + druid

sharding-jdbc-spring-boot-starter 整合 mybatis-plus-boot-starter + druid

sharding-jdbc整合 mybatis-plus + druid

shardingsphere分库分表

================================

©Copyright 蕃薯耀 2020-10-21

https://www.cnblogs.com/fanshuyao/

一、环境:


  org.springframework.boot
  spring-boot-starter-parent
  2.2.10.RELEASE
  

3.4.0
4.1.1

        
        
        
            com.alibaba
            druid
            1.2.1
        
        
        
            org.apache.shardingsphere
            sharding-jdbc-spring-boot-starter
            ${shardingsphere.version}
        
        
        
            mysql
            mysql-connector-java
        
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.1.2
        
        
        
            org.springframework.boot
            spring-boot-starter-freemarker
        
        
        
            com.github.pagehelper
            pagehelper-spring-boot-starter
            1.2.13
        
        
        
            com.baomidou
            mybatis-plus-boot-starter
            ${mybatisPlus.version}
        
        
        
        
            com.baomidou
            mybatis-plus-generator
            ${mybatisPlus.version}
        
        
        
        
            org.projectlombok
            lombok
            provided
        

数据源连接配置:

#com.alibaba.druid.pool.DruidDataSource
#DruidDataSource需要引入druid的Jar包,使用:url
#com.zaxxer.hikari.HikariDataSource
#HikariDataSource要使用:jdbc-url
spring.shardingsphere.datasource.ss1.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.ss1.driver-class-name=com.mysql.cj.jdbc.Driver
spring.shardingsphere.datasource.ss1.url=jdbc:mysql://localhost:3306/ss1?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8&pinGlobalTxToPhysicalConnection=true&autoReconnect=true&nullNamePatternMatchesAll=true
spring.shardingsphere.datasource.ss1.username=root
spring.shardingsphere.datasource.ss1.password=root

注意:

不能使用:druid-spring-boot-starter,不然会导致下面的问题:java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
    at org.springframework.util.Assert.notNull(Assert.java:201)
    at org.mybatis.spring.support.SqlSessionDaoSupport.checkDaoConfig(SqlSessionDaoSupport.java:122)
    at org.mybatis.spring.mapper.MapperFactoryBean.checkDaoConfig(MapperFactoryBean.java:73)
    at org.springframework.dao.support.DaoSupport.afterPropertiesSet(DaoSupport.java:44)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790)
    ... 47 more

sharding-jdbc-spring-boot-starter 整合 mybatis-plus-boot-starter + druid_第1张图片

(如果文章对您有帮助,欢迎捐赠,^_^)

================================

©Copyright 蕃薯耀 2020-10-21

https://www.cnblogs.com/fanshuyao/

你可能感兴趣的:(mybatis,mysql,java,spring,spring,boot)