Error Records
1.
Description:
Failed to configure a DataSource: 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).
A:
检查application.properties中的数据库相关配置是否有误,pom.xml文件中是否有依赖冲突,
如果都是OK的,那就去pom.xml中添加如下配置,参考出处
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.yml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.yml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
2.Field xx in xx required a bean of type 'xxxMapper' that could not be found问题
A:添加@MapperScan("com.xxx.xxx"),检查service的impl类有没有添加@service注解
3.本地数据库连接不上,报错
2003 - Can't connect to MySQL server on '127.0.0.1' (61 "Connection refused")
A:
关闭mysql服务:苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务(点击stop mysql server)或者使用命令:sudo /usr/local/mysql/support-files/mysql.server stop,强制关闭;
进入终端输入:cd /usr/local/mysql/bin
回车后 登录管理员权限 sudo su (输入你电脑的密码)
回车后输入以下命令来禁止mysql验证功能: ./mysqld_safe --skip-grant-tables
回车后mysql会自动重启(偏好设置中mysql的状态会变成running)
输入命令 ./mysql
回车后,输入命令 FLUSH PRIVILEGES;
回车后,输入命令 ALTER user 'root'@'localhost' IDENTIFIED BY '123456'
重启mysql:sudo /usr/local/mysql/support-files/mysql.server restart
4.SpringBoot 查询时间数据 数据库和返回数据相差8个小时,解决办法
public class ArticleListVo {
private Long articleId;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
private Date createTime;
}
5.springboot中配置addResourceHandler和addResourceLocations,springboot无法读取静态资源
找到继承WebMvcConfigurationSupport的类,配置如下:
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
registry.addResourceHandler("swagger-ui.html")
.addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**")
.addResourceLocations("classpath:/META-INF/resources/webjars/");
}
swagger如果没有用到,可以删除
6.接口返回$ref":"$.data.***
FastJson的JSONArray类型作为返回数据,当像JSONArray对象中添加JSONObject对象,而JSONObject对象中包含相同的节点数据时,FastJson会防止返回数据栈溢出的问题,自动将JSONArray中相同的节点数据使用引用方式代替。将返回的List转Object,JSONArray.toJSON。或者在循环里重新new 一个对象,用new 出来的对象放到子list