错误消息
springboot2启动项目报错,应该是数据库连接的问题,导致无法启动。
错误消息如下:
-
***************************
-
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).
解决方法
不需要连接数据库
********************************** 项目不需要连接数据库,启动报错 ******************************************
解决方法如下:
只要在将@SpringBootApplication修改为@SpringBootApplication(exclude= {})就可以启动的时候不需要连接数据库。
-
// 这里需要注意Springboot版本
-
// 下面的配置只对起作用
-
// 如果是,需要把中引用的jdbc驱动注释掉
-
// 如果是,需要把中引用的mybatis或者mybatis-plus注释掉
-
@SpringBootApplication(exclude= {})
需要连接数据库
********************************** 需要连接数据库,启动报错 ******************************************
解决方法如下:
第一种
yml配置示例如下
-
#在/或者文件中没有添加数据库配置信息.
-
spring:
-
datasource:
-
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false
-
username: root
-
password: 123456
-
driver-class-name:
第二种
properties文件示例如下
= jdbc:mysql://localhost:3306/test?setUnicode=true&characterEncoding=utf8
第三种
mysql的版本不同,示例如下
-
#mysql8以下的版本,请检查文件种依赖的mysql jar包的版本
-
driver-class-name:
-
-
#mysql8以下的url写法
-
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false
-
-
-
-
-
-
#mysql8的版本写法,多了个cj
-
driver-class-name:
-
-
#同时mysql8的url也需要加入时区,参照如下
-
url: jdbc:mysql://192.168.1.110:3306/test?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=Asia/Shanghai&useSSL=false&allowMultiQueries=true&allowPublicKeyRetrieval=true
第四种
项目没有加载到yml或者properties文件,特别是自己的pom打包是jar的项目,请查看自己的文件中的packaging
<packaging>jar</packaging>
如果pom中指定使用jar,系统不会自动读取到yml或者properties文件的,需要我们手动配置。
-
<!--build放在</dependencies>标签的后面,主要加入的是resources标签 -->
-
<!--resources标签可以告诉系统启动的时候能够读取到这些后缀的文件 -->
-
<build>
-
<plugins>
-
<plugin>
-
<groupId></groupId>
-
<artifactId>spring-boot-maven-plugin</artifactId>
-
</plugin>
-
</plugins>
-
<resources>
-
<resource>
-
<directory>src/main/java</directory>
-
<includes>
-
<include>**/*.yml</include>
-
<include>**/*.properties</include>
-
<include>**/*.xml</include>
-
</includes>
-
<filtering>false</filtering>
-
</resource>
-
<resource>
-
<directory>src/main/resources</directory>
-
<includes>
-
<include>**/*.yml</include>
-
<include>**/*.properties</include>
-
<include>**/*.xml</include>
-
</includes>
-
<filtering>false</filtering>
-
</resource>
-
<resource>
-
<directory>lib</directory>
-
<includes>
-
<include>**/*.jar</include>
-
</includes>
-
</resource>
-
</resources>
-
</build>
第五种
项目使用了springcloud+nacos系列,启动项目时候需要手动指定【--=test】,那么在resources文件夹下就必须要有或者文件,同时配置文件中连接的nacos地址里面也必须配置对应的命名空间,和对应服务名称的yml文件,否则也是报错。下面是配置文件的截图
第六种
如果你的所有配置信息都是好的,也就是说项目之前是好的,现在突然不行了。可以尝试清除缓存。点击File-Invalidata Caches...接下来工具会重启,重新启动后maven-clean以下试试。
第七种
注意如果使用了nacos这种配置的,一定要注意自己的yml或者properties文件中的spring引入的位置是在nacos的配置地址上面还是下面,下面的文件会把上面的配置覆盖掉,导致失效。
第八种
yml或者properties文件放错位置或者maven编译的时候没有把文件同步到target下面。
结束
-----华丽的分割线,以下是凑字数,大家不用花时间看,快去改代码-----
-----华丽的分割线,以下是凑字数,大家不用花时间看,快去改代码-----
-----华丽的分割线,以下是凑字数,大家不用花时间看,快去改代码-----
-
package cn.;
-
-
import .slf4j.Slf4j;
-
-
@Slf4j
-
public class MakeUpTheWordCount {
-
-
private String make_up_the_word_count_column_999999999_1;
-
private String make_up_the_word_count_column_999999999_2;
-
private String make_up_the_word_count_column_999999999_3;
-
private String make_up_the_word_count_column_999999999_4;
-
private String make_up_the_word_count_column_999999999_5;
-
private String make_up_the_word_count_column_999999999_6;
-
private String make_up_the_word_count_column_999999999_7;
-
private String make_up_the_word_count_column_999999999_8;
-
private String make_up_the_word_count_column_999999999_9;
-
private String make_up_the_word_count_column_999999999_10;
-
private String make_up_the_word_count_column_999999999_11;
-
private String make_up_the_word_count_column_999999999_12;
-
private String make_up_the_word_count_column_999999999_13;
-
private String make_up_the_word_count_column_999999999_14;
-
private String make_up_the_word_count_column_999999999_15;
-
private String make_up_the_word_count_column_999999999_16;
-
private String make_up_the_word_count_column_999999999_17;
-
private String make_up_the_word_count_column_999999999_18;
-
private String make_up_the_word_count_column_999999999_19;
-
private String make_up_the_word_count_column_999999999_20;
-
-
public String getMake_up_the_word_count_column_999999999_1() {
-
return make_up_the_word_count_column_999999999_1;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_1(String make_up_the_word_count_column_999999999_1) {
-
this.make_up_the_word_count_column_999999999_1 = make_up_the_word_count_column_999999999_1;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_2() {
-
return make_up_the_word_count_column_999999999_2;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_2(String make_up_the_word_count_column_999999999_2) {
-
this.make_up_the_word_count_column_999999999_2 = make_up_the_word_count_column_999999999_2;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_3() {
-
return make_up_the_word_count_column_999999999_3;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_3(String make_up_the_word_count_column_999999999_3) {
-
this.make_up_the_word_count_column_999999999_3 = make_up_the_word_count_column_999999999_3;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_4() {
-
return make_up_the_word_count_column_999999999_4;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_4(String make_up_the_word_count_column_999999999_4) {
-
this.make_up_the_word_count_column_999999999_4 = make_up_the_word_count_column_999999999_4;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_5() {
-
return make_up_the_word_count_column_999999999_5;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_5(String make_up_the_word_count_column_999999999_5) {
-
this.make_up_the_word_count_column_999999999_5 = make_up_the_word_count_column_999999999_5;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_6() {
-
return make_up_the_word_count_column_999999999_6;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_6(String make_up_the_word_count_column_999999999_6) {
-
this.make_up_the_word_count_column_999999999_6 = make_up_the_word_count_column_999999999_6;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_7() {
-
return make_up_the_word_count_column_999999999_7;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_7(String make_up_the_word_count_column_999999999_7) {
-
this.make_up_the_word_count_column_999999999_7 = make_up_the_word_count_column_999999999_7;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_8() {
-
return make_up_the_word_count_column_999999999_8;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_8(String make_up_the_word_count_column_999999999_8) {
-
this.make_up_the_word_count_column_999999999_8 = make_up_the_word_count_column_999999999_8;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_9() {
-
return make_up_the_word_count_column_999999999_9;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_9(String make_up_the_word_count_column_999999999_9) {
-
this.make_up_the_word_count_column_999999999_9 = make_up_the_word_count_column_999999999_9;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_10() {
-
return make_up_the_word_count_column_999999999_10;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_10(String make_up_the_word_count_column_999999999_10) {
-
this.make_up_the_word_count_column_999999999_10 = make_up_the_word_count_column_999999999_10;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_11() {
-
return make_up_the_word_count_column_999999999_11;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_11(String make_up_the_word_count_column_999999999_11) {
-
this.make_up_the_word_count_column_999999999_11 = make_up_the_word_count_column_999999999_11;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_12() {
-
return make_up_the_word_count_column_999999999_12;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_12(String make_up_the_word_count_column_999999999_12) {
-
this.make_up_the_word_count_column_999999999_12 = make_up_the_word_count_column_999999999_12;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_13() {
-
return make_up_the_word_count_column_999999999_13;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_13(String make_up_the_word_count_column_999999999_13) {
-
this.make_up_the_word_count_column_999999999_13 = make_up_the_word_count_column_999999999_13;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_14() {
-
return make_up_the_word_count_column_999999999_14;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_14(String make_up_the_word_count_column_999999999_14) {
-
this.make_up_the_word_count_column_999999999_14 = make_up_the_word_count_column_999999999_14;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_15() {
-
return make_up_the_word_count_column_999999999_15;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_15(String make_up_the_word_count_column_999999999_15) {
-
this.make_up_the_word_count_column_999999999_15 = make_up_the_word_count_column_999999999_15;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_16() {
-
return make_up_the_word_count_column_999999999_16;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_16(String make_up_the_word_count_column_999999999_16) {
-
this.make_up_the_word_count_column_999999999_16 = make_up_the_word_count_column_999999999_16;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_17() {
-
return make_up_the_word_count_column_999999999_17;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_17(String make_up_the_word_count_column_999999999_17) {
-
this.make_up_the_word_count_column_999999999_17 = make_up_the_word_count_column_999999999_17;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_18() {
-
return make_up_the_word_count_column_999999999_18;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_18(String make_up_the_word_count_column_999999999_18) {
-
this.make_up_the_word_count_column_999999999_18 = make_up_the_word_count_column_999999999_18;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_19() {
-
return make_up_the_word_count_column_999999999_19;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_19(String make_up_the_word_count_column_999999999_19) {
-
this.make_up_the_word_count_column_999999999_19 = make_up_the_word_count_column_999999999_19;
-
}
-
-
public String getMake_up_the_word_count_column_999999999_20() {
-
return make_up_the_word_count_column_999999999_20;
-
}
-
-
public void setMake_up_the_word_count_column_999999999_20(String make_up_the_word_count_column_999999999_20) {
-
this.make_up_the_word_count_column_999999999_20 = make_up_the_word_count_column_999999999_20;
-
}
-
}