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