SpringBoot项目开发中遇到的问题总结
1.报数据库未配置或配置错误
1.报错信息如下:Fild to configure a DataSource:'url' attribute is not specified and no embedded datasource could be configured. Reason: Failed to determine a suitable driver classs
基本是说数据库没有配置或者url配置错误的问题,网上解决方案基本也是基于是围绕着两个。
尝试了个遍,还是报这个错误,数据库配置了,url也没问题,因为新建项目就能正常,放到当前项目就一直报该错误,后来发现是resources目录没有设置为资源目录导致的,典型的特征就是Resources目录没有小黄标。
错误的如下:
正常应该是:
解决方案:
我们需要打开File->Poroject Structure->Modules->Sources,展开目录找到resources目录将其置为Resources,如下:
然后apply->save就可以了。
2.mybatis puls报错Error creating bean with name 报错信息类似: org.springframework.beans.factory.unsatisfieddependencyexception: Error creating bean with name....
导致这一问题的可能有很多,我说下我遇到的情况。
首先application.yml中配置的mapper-locations:classpath*:com/inagora/dao/mapper/xml/*Mapper.xml没有问题
最后发现项目的target目录下压根没有mapper.xml文件,也就是说springboot容器根本没有把mapper.xml文件打包进项目。
解决方案: pom.xml加入如下配置(根据自己项目的目录配置mapper.xml路径)
<!-- 项目打包时会将java目录中的*.xml文件也进行打包 -->
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>com/inagora/dao/mapper/xml/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>