转载:springboot项目运行时报错:HikariPool-1 - Exception during pool initializ

 目录

前言:

场景分析一:HikariPool-1 - Exception during pool initialization.

原因分析

解决办法

场景分析二: Application run failed

问题描述

原因分析

解决办法

场景分析三:Application run failed

原因分析 

解决办法

总结:


前言:

有报错不怕,怕的是不知道怎么解决

场景分析一:HikariPool-1 - Exception during pool initialization.

我们先来看一下报错截图:

编辑他说的是HikariPool-1-池初始化期间出现异常,而导致项目启动失败。


原因分析

JDBC连接失败


解决办法


第一步:检查application.yaml里面的url后3306/(数据库名字),检查自己数据库里有没有这个名字。
第二步:检查username和password和当时设计数据库的时候是不是一样的,通常我们在设计时用root、123456。因为你新导进一个项目的时候这些东西很容易忘改而报错。所以要查看地址、端口、数据库名字和自己的是不是一样。

另外如果你使用的是SpringBoot 2.0以上版本

应配置为driver‐class‐name: com.mysql.cj.jdbc.Driver

spring: 
datasource:
    #                              //地址     端口   数据库名字
    url: jdbc:mysql://${MYSQL_HOST:localhost}:3306/studentmanagement
    username: root
    password: 123456
    driver-class-name: com.mysql.cj.jdbc.Driver

在我们改完后我们再来检查一下运行:

项目运行成功!

场景分析二: Application run failed

SpringBoot 服务启动的时候报错:

下面是错误报告我用回车隔开方便检查

这个问题遇到好多次了,一直没能记录下来,今天又碰到了

Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
ERROR 1572 — [ restartedMain] o.s.boot.SpringApplication : Application run failed


问题描述

 Error creating bean with name 'userAction': 
Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.

UnsatisfiedDependencyException: Error creating bean with name 'userServiceImpl': 
Unsatisfied dependency expressed through field 'mapper'; 
nested exception is org.springframework.beans.factory.

UnsatisfiedDependencyException: Error creating bean with name 'userMapper' defined in file[E:\桌面\springbootdemo\target\classes\cn\edu\neu\springbootdemo\mapper\UserMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; 

nested exception is org.springframework.beans.factory.

BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; 

nested exception is org.springframework.beans.
BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.

NestedIOException: Failed to parse mapping resource: 'file [E:\桌面\springbootdemo\target\classes\mapper\UserMapper.xml]'; 

nested exception is org.apache.ibatis.builder.
BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 36;
在 XML 声明中的编码伪属性前面必须有空格。

原因分析

原因分析:Caused by
这个问题得具体问题具体分析,得看下面那些报错什么意思,不能直接去网上找解决办法
刚才也是找了好多博主写的文章都没解决
比如说我的报错信息是:
创建名为 "userAction" 的 bean 时出错
创建名为 "userServiceImpl" 的bean时出错
定义的名为 "sqlSessionFactory" 的bean时出错
在 XML格式声明中的编码伪属性前面必须有空格


解决办法

检查代码

场景分析三:Application run failed

​编辑

报错代码:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

2022-10-14 13:15:21.461 ERROR 12548 --- [           main] o.s.boot.SpringApplication               : Application run failed

原因分析 

往下看原因:Caused by: 

下面是错误报告我用回车隔开方便检查

Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/baomidou/mybatisplus/spring/boot/starter/MybatisPlusAutoConfiguration.class]: 
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: 
Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: 
Factory method 'sqlSessionFactory' threw exception; 
nested exception is com.baomidou.mybatisplus.exceptions.MybatisPlusException: 
Error: GlobalConfigUtils setMetaData Fail !  
Cause:java.sql.SQLSyntaxErrorException: Unknown database 'jiakao'

重点在最后一句,他说我这个错误是:GlobalConfigUtils setMetaData失败!

原因:java.sql    SQLSyntaxErrorException:未知数据库“jiakao”

解决办法

上面的错误说数据库名字不对

根据 Navicat或 VS Code数据库可视化工具一看,是数据库名字打错了

果然数据库名字一改后,立马跑通

总结:

重要的不是问题解决了,重要的是解决问题的过程
还有error才会影响程序的运行,warning警告不用管
根据错误的提示去想,为什么找不到这个bean/class?通过这个错误一步步去跟踪,找到根本的原因,这是积累知识的过程
等以后这种问题发现地慢慢的多起来,慢慢地积累起来,积累的经验越多越好
英语很重要,不仅仅是处理问题的时候、出错的时候、分析问题的时候都是英文

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值