Failed to configure a DataSource: ‘url‘ attribute is not specified and no Reaso(附解决思路)

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
 If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
 If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

扫描不到我尝试了网上全部的方式:

第一种对我而言无意义我本来是要的;

@MapperScan("com.wsc.core.mapper")//映射mapper地址
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})  //启动类 SpringBoot
public class Start {
    public static void main(String[] args) {
        SpringApplication.run(Start.class,args);
    }
}

第二种说 application写的有问题 但我写的是ok 的 检查了好几次了

# sharding-jdbc 水平分表策略
# 配置数据源,给数据源起别名  m1 起的名字随意单要和下面的一致
spring.shardingsphere.datasource.names=m1

# 一个实体类对应两张表,覆盖
spring.main.allow-bean-definition-overriding=true

# 配置数据源的具体内容,包含连接池,驱动,地址,用户名,密码  druid单独配置
spring.shardingsphere.datasource.m1.type=com.alibaba.druid.pool.DruidDataSource
#com.mysql.cj.jdbc.Driver 8版本      我本地数据版本低 5.7
spring.shardingsphere.datasource.m1.driver-class-name=com.mysql.cj.jdbc.Driver
#高版本加入了时区  jdbc:mysql://localhost:3306/course_db?serverTimezone=GMT%2B8
spring.shardingsphere.datasource.m1.url=jdbc:mysql://127.0.0.1:3306/course_db?serverTimezone=GMT%2B8
spring.shardingsphere.datasource.m1.username=root
spring.shardingsphere.datasource.m1.password=root
# 指定course表分布的情况,配置表在哪个数据库里,表的名称都是什么  course 表规则(暂时这么理解)  m1.course_$->{1..2}=m1.course_1,m1.course_2
spring.shardingsphere.sharding.tables.course.actual-data-nodes=m1.course_$->{1..2}

# 指定 course 表里面主键 cid 的生成策略| SNOWFLAKE 雪花算法生成一个唯一的字符串
spring.shardingsphere.sharding.tables.course.key-generator.column=cid
spring.shardingsphere.sharding.tables.course.key-generator.type=SNOWFLAKE

# 配置分表策略    约定 cid 值偶数添加到 course_1 表,如果 cid 是奇数添加到 course_2 表
spring.shardingsphere.sharding.tables.course.table-strategy.inline.sharding-column=cid
#这部分理解起来比较复杂我这边就啰嗦下:course_$->{cid % 2 + 1}    course_也是相当于对应表空间m1.course_1
#cid 是他的主键的iD cid % 2 + 1  举例说明下: 当cid =(偶数)4/2余0 0+1=1 那么他的数据就在  course_1 中,上面指定了2个 1.course_$->{1..2}
#其余的结果就都匹配上面的 2 我理解的就是 不满足条件1 就都是条件2的东西
spring.shardingsphere.sharding.tables.course.table-strategy.inline.algorithm-expression=course_$->{cid % 2 + 1}
# 打开 sql 输出日志
spring.shardingsphere.props.sql.show=true

第三种检查jar包也是有的

   <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid-spring-boot-starter</artifactId>
                <version>1.1.14</version>
            </dependency>

第五种 考虑到是不是扫描不到资源啥的问题;

在这里插入图片描述
第六种 看了网上有pom 加入配置的好多人都管用我试了试;

   <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
        <!--新增加入的 -->


        <resources>



            <resource>

                <!--指定根目录 到源文件夹 一般如下-->

                <directory>src/main/java</directory>

                <includes>

                    <include>**/*.yml</include>

                    <include>**/*.yaml</include>

                    <include>**/*.xml</include>

                    <include>**/*.properties</include>

                </includes>

                <filtering>false</filtering>

            </resource>

            <resource> <!--指定根目录 到源文件夹 一般如下-->

                <directory>src/main/resources</directory>

                <includes>

                    <include>**/*.yml</include>

                    <include>**/*.yaml</include>

                    <include>**/*.xml</include>

                    <include>**/*.properties</include>

                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
   <!--新增加入的 -->
    </build>



第七种 看了网上有pom 加入配置的好多人都管用我试了试;
我已经快崩溃了了…

自己静下心来仔细的前后过了一次 想的是不是spring boot jar之类的一些依赖问题导致最后果然如此;

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

**sharding 这是我这边分库分表的maven;严格按照版本号来吧 **

<dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
            <version>4.0.0-RC1</version>
        </dependency>

到这就解决了;继续学习下面的

在这里插入图片描述

欢迎补充…

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

默 语

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值