这个异常的问题源比较多,所以如果我的方法不能解决,请自行百度其他方法
文章目录
项目场景一: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
问题描述:
SpringBoot 服务启动的时候报错:
下面是错误报告我用回车隔开方便检查
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 声明中的编码伪属性前面必须有空格。
原因分析:
这个问题得具体问题具体分析,得看下面那些报错什么意思,不能直接去网上找解决办法
刚才也是找了好多博主写的文章都没解决
比如说我的报错信息是:
创建名为 “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?通过这个错误一步步去跟踪,找到根本的原因,这是积累知识的过程
等以后这种问题发现地慢慢的多起来,慢慢地积累起来,积累的经验越多越好
英语很重要,不仅仅是处理问题的时候、出错的时候、分析问题的时候都是英文