关于解决springcloud 创建bean失败的问题

今天学习springcloud的时候,手动导入关于springboot和springcloud的jar包,启动代码的时候发现出了一大段问题:

2022-09-14 22:30:38.800 ERROR 15520 --- [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'deptController': Unsatisfied dependency expressed through field 'deptService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'deptServiceImpl': Unsatisfied dependency expressed through field 'deptDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'deptDao' defined in file [C:UsersCharonIdeaProjectsspringcloudspringcloud-provider-dept-8001 argetclassescomspringcloudDaoDeptDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfigurationKaTeX parse error: Can't use function '\]' in math mode at position 14: Generic.class\̲]̲: Bean instanti...AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:659) ~[spring-beans-5.3.22.jar:5.3.22]

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessorKaTeX parse error: Undefined control sequence: \[ at position 78: ...sor.java:639) ~\̲[̲spring-beans-5....doGetBeanKaTeX parse error: Undefined control sequence: \[ at position 34: ...ory.java:335) ~\̲[̲spring-beans-5....Generic.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.boot.jdbc.EmbeddedDatabaseConnection.isEmbedded(Ljava/lang/String;)Z

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessorKaTeX parse error: Undefined control sequence: \[ at position 89: ...sor.java:659) ~\̲[̲spring-beans-5....AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:639) ~[spring-beans-5.3.22.jar:5.3.22]

at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:119) ~[spring-beans-5.3.22.jar:5.3.22]

at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:399) ~[spring-beans-5.3.22.jar:5.3.22]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1431) ~[spring-beans-5.3.22.jar:5.3.22]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:619) ~[spring-beans-5.3.22.jar:5.3.22]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.22.jar:5.3.22]

at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBeanKaTeX parse error: Undefined control sequence: \[ at position 34: ...ory.java:335) ~\̲[̲spring-beans-5....AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:656) ~[spring-beans-5.3.22.jar:5.3.22]

... 20 common frames omitted

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'deptDao' defined in file [C:UsersCharonIdeaProjectsspringcloudspringcloud-provider-dept-8001 argetclassescomspringcloudDaoDeptDao.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfigurationKaTeX parse error: Can't use function '\]' in math mode at position 14: Generic.class\̲]̲: Bean instanti...doGetBeanKaTeX parse error: Undefined control sequence: \[ at position 34: ...ory.java:335) ~\̲[̲spring-beans-5....AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:656) ~[spring-beans-5.3.22.jar:5.3.22]

... 34 common frames omitted

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfigurationKaTeX parse error: Can't use function '\]' in math mode at position 14: Generic.class\̲]̲: Bean instanti...doGetBeanKaTeX parse error: Undefined control sequence: \[ at position 34: ...ory.java:335) ~\̲[̲spring-beans-5....Generic.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.boot.jdbc.EmbeddedDatabaseConnection.isEmbedded(Ljava/lang/String;)Z

at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.22.jar:5.3.22]

at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-5.3.22.jar:5.3.22]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.22.jar:5.3.22]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.22.jar:5.3.22]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.22.jar:5.3.22]

at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.22.jar:5.3.22]

at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBeanKaTeX parse error: Undefined control sequence: \[ at position 34: ...ory.java:335) ~\̲[̲spring-beans-5....Generic.dataSource(DataSourceConfiguration.java:122) ~[spring-boot-autoconfigure-2.3.0.RELEASE.jar:2.3.0.RELEASE]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_342]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_342]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_342]

at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_342]

at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.22.jar:5.3.22]

... 73 common frames omitted

上网查到了许多解决方案,进行逐一尝试

1、相关的注释没给到位

重复检查controller层的@Restcontroller service层的@service 和dao层的@mapper,发现没有任何错误,不是这个问题

2、yml配置文件出错

先检查yml配置文件的内容,datasource没问题,mybatis的配置也没问题,排除内容出错,上网查到了可能是配置文件的路径发生错误,yml没有读取到,重复更改yml的路径,甚至使用propreties文件,也没能解决问题,于是排除配置文件的问题

3.发生版本冲突

可能使用pom的时候导入的springboot和springcloud发生冲突,或者重复导入多个jar包,idea不知道识别哪一个文件,查看所有依赖的版本,发现springboot的版本和spring的版本都有重复,且不一致,还可能与springcloud的版本发生冲突,于是查询最适合的springboot版本和与其对应的springcloud的版本,1、SpringCloud: Hoxton.SR8

2、SpringBoot:2.3.3.RELEASE

重新创建一个maven,并将之前的代码复制粘贴,只改变springboot和springcloud的版本,最后成功运行

相关推荐
程序员爱钓鱼3 小时前
GoHTML解析利器:github.com/PuerkitoBio/goquery实战指南
后端·google·go
golang学习记3 小时前
从“大泥球“到模块化单体:Spring Modulith + IntelliJ IDEA 拯救你的代码
后端·intellij idea
颜酱3 小时前
一步步实现字符串计算器:从「转整数」到「带括号与优化」
javascript·后端·算法
离开地球表面_993 小时前
金三银四程序员跳槽指南:从简历到面试再到 Offer 的全流程准备
前端·后端·面试
UrbanJazzerati3 小时前
Scrapling入门指南:零基础也能学会的网页抓取神器
后端·面试
张洪权3 小时前
mysql + nest.js 加锁 搞并发问题
后端
郡杰3 小时前
MyBatisPlus
后端
beata3 小时前
Java基础-18:Java开发中的常用设计模式:深入解析与实战应用
java·后端
Qlly3 小时前
DDD 架构为什么适合 MCP Server 开发?
人工智能·后端·架构
苏三说技术4 小时前
Prompt、Agent、Function Call、Skill、MCP,傻傻分不清楚?
后端