idea报错记录和解决方案


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).

2.解决方案:

1.先仔细对比了下,发现是yml中数据源位置没对好,把datasource和spring对应到一列上去了。

改好格式之后发现,driver和datasource都报红,看了半天,

原来是pom文件中引入的mysql依赖和druid依赖给注释了,后来放开,就没有报上面的错了。

参考:

https://www.cnblogs.com/wangshichang/p/11418818.html

https://blog.csdn.net/weixin_57107764/article/details/118901097

https://zhuanlan.zhihu.com/p/257275319

报错2:

FileNotFoundException: class path resource [config/mybatis.xml] cannot be opened because it does not exist

但是目录中是有该文件的。

看参考博客,原来是springboot2.x以上,不需要指定mybatis配置文件,修改如下:

1
2
3
4
5
6
7
mybatis:

指定全局配置文件位置 --不需要mybatis-config.xml

config-location: classpath:config/mybatis.xml #mybatis 配置文件路径

type-aliases-package: com.mybatistest.model # entity别名类所在包
mapper-locations: com/mybatistest/dao/*.xml # mapper映射文件
configuration:
map-underscore-to-camel-case: true
然后启动就没有报错了。

参考:

https://www.codeleading.com/article/98622520245/

报错3:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.mybatistest.dao.EmployeeDao.getAllEmps

重新修改pom文件,将resource下的yml文件和xml文件都加入了target下(已经显示有),还是报同样错。

1
2
3
4
5
6
7
8
9
10
11
12
13



src/main/resources

.yml
.properties
**/*.xml

false


**一个非常非常容易忽视的常见错误,又给碰上了:

本质原因,还是从dao去找dao.xml文件没找到。原因原来是:

两个目录在项目里面,看着是一样的,但是去项目根目录下就会发现很大不一样。

进入项目根目录:

1.发现接口是标准3级目录

2.发现xml文件居然是一级目录

现在才回想起来,当时新建文件时,图手快,直接复制一下新建成的,导致出现这样的问题,也是排查了好长时间。

总结:在各种需要查找路径去找文件(比如xml,Excel模板)的地方,也就是只要有写路径的地方,都需要注意这个问题。

一般出现: 二者路径看着死活没问题,但是就是一直报错的情况,就可以先去项目根目录下比对一下路径,或许就可以解决了。

参考博客:https://blog.csdn.net/sundacheng1989/article/details/81630370

https://blog.csdn.net/q_0718/article/details/79608423

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值