Springboot+mybatis+druid常见问题

1. 配置文件问题,导致这个问题的原因是,我的springboot应用pom中没有增加SpringCloud的依赖,配置文件名使用的是bootstrap.yml(SpringCloud应用才能识别bootstrap配置文件),所以应用在读取数据库连接信息时直接没有找到。

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

解决办法:bootstrap.yml改为application.yml,或者增加SpringCloud相关依赖。

2. Invalid bound statement (not found)

2.1

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.hollysysdigital.modellib.mapper.FileInfoMapper.insertFileAttachInfo

{
  "timestamp": "2018-12-15T03:21:10.712+0000",
  "status": 500,
  "error": "Internal Server Error",
  "message": "Invalid bound statement (not found): com.hollysysdigital.modellib.mapper.FileInfoMapper.insertFileAttachInfo",
  "path": "/file/saveBackFile"
}

原因:还是配置文件的原因!

错误配置,把mybatis相关配置放到了spring的下面,相当于spring.mybatis.mapper-locations=xxxx

正确的配置应该是:mybatis.mapper-locations=xxxx

注意:yml配置文件看起来比较优雅,但使用的时候多个空格可能就导致配置项的key的值就成了上面的配置项的下级配置了,所以,yml作为配置文件,一定要好好检查。

2.2  mapper的namespace和实际的类路径不一致(复制粘贴导致的)

2.3  id与mapper接口中的方法名不一致

3. 虽然Idea会提示,exclude={DruidDataSourceAutoConfigure.class} 这一句应该加到@SpringBootApplication上面,并且给你一个红色波浪线错误提示,但是你这样做了之后,应用就启动不起来了。

去掉 @EnableAutoConfiguration(exclude={DruidDataSourceAutoConfigure.class})  之后启动异常如下:

Caused by: java.lang.ClassNotFoundException: org.springframework.boot.bind.RelaxedDataBinder

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值