org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gen

本文解析了在SpringBoot项目中整合Redis时遇到的UnsatisfiedDependencyException异常,详细介绍了错误原因及解决步骤,包括添加依赖和配置Redis相关属性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'generateToken': Unsatisfied dependency expressed through field 'redisUtil'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'redisUtil' defined in file [C:\Mytool\Test\springboot\springboot_demos\meite-shop-parent\meite-shop-common\meite-shop-common-core\target\classes\com\pk\common\core\utils\RedisUtil.class]: Post-processing of merged bean definition failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [com.pk.common.core.utils.RedisUtil] from ClassLoader [sun.misc.Launcher$AppClassLoader@14dad5dc]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1378) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:575) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
 

遇到这个问题先要冷静,仔细看日记

日记大概意思就是 :redisUtil dependency 有问题........我仔细想了下原来我依赖的common里面redisutil 类用了redis

结果 我这web 项目里面没有添加依赖.....

解决:

我的问题解决: 加入依赖和配置文件

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
 </dependency>
redis:
        host: 地址
        port: 6379
        database: 0
        timeout: 60s  # 数据库连接超时时间,2.0 中该参数的类型为Duration,这里在配置的时候需要指明单位
        # 连接池配置,2.0中直接使用jedis或者lettuce配置连接池
        jedis:
          pool:
            # 最大空闲连接数
            max-idle: 500
            # 最小空闲连接数
            min-idle: 2
            # 等待可用连接的最大时间,负数为不限制
            max-wait:  -1s
            # 最大活跃连接数,负数为不限制
            max-active: -1

Error creating bean 这种错误解决思路:

1.仔细看日记

2, 冷静仔细去找你注入的地方注解是否有 和 你的启动类是否是在utils类的上级,注入一定要在启动类同级或下级才能扫到注解

3,网上找找

 

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'genController': Unsatisfied dependency expressed through field 'genTableService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'genTableServiceImpl': Unsatisfied dependency expressed through field 'genTableMapper'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'genTableMapper' defined in file [D:\mxktech\cnooc-hg\RuoYi-Cloud-master\ruoyi-modules\ruoyi-gen\target\classes\com\ruoyi\gen\mapper\GenTableMapper.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 [com/baomidou/mybatisplus/autoconfigure/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 org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\mxktech\cnooc-hg\RuoYi-Cloud-master\ruoyi-modules\ruoyi-gen\target\classes\mapper\generator\GenTableColumnMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [D:\mxktech\cnooc-hg\RuoYi-Cloud-master\ruoyi-modules\ruoyi-gen\target\classes\mapper\generator\GenTableColumnMapper.xml]'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'GenTableColumn'. Cause: java.lang.ClassNotFoundException: Cannot find class: GenTableColumn 什么意思
07-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值