org.springframework.beans.factory.UnsatisfiedDependencyException异常
来源:互联网 发布:qq三国js技能展示 编辑:程序博客网 时间:2024/06/05 07:32
关于Spring中org.springframework.beans.factory.UnsatisfiedDependencyException异常
解决办法1:
我自己的原因是:<!-- parameterType不能是resultMap的Id=“BaseResultMap” 因为mybatis不能识别BaseResultMap 是什么 -->
这个异常是由于在applicationContext.xml中关于bean的autowirte装配类型,在类型byName,byType,constructor三种类型中,可能会出现因无法自动装配而产生题目中的异常。
下面介绍一下关于autowrite的集中装配类型:
1)no:采用自动装配。必须使用ref直接饮用其他Bean<ref bean="JavaBean"/>
2)byName:以属性名区分自动装配。在容器中寻找与JavaBean属性名相同的JavaBean,并假期自动装配到JavaBean中。
3)byType:以属性类型区分自动转配
4)constructor:通过构造方法的参数类型自动装配
5)autudetect:首先使用constructor方式自动装配,然后使用byType方式
在使用自动装配的时候,吧容易出现问题的JavaBean采用手动装配。
解决办法2:
一、错误描述:
此错误导致了web 应用无法启动,根据日志内容分析该问题属于spring配置问题。
二、具体错误信息:
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'redisDao' defined in ServletContext resource [/WEB-INF/classes/dataSource-bean.xml]: Unsatisfied dependency expressed through constructor argument with index 1 of type [Java.util.Set]: Ambiguous constructor argument types - did you specify the correct bean references as constructor arguments?
三、解决方法
查询Spring配置文件,发现index=“1”的参数,使用了重复的定义。根据SPRING的注入规则,constructor-arg 中不能同时出现 index\name\type的定义。如下:
<beanid="redisDao"class="com.aspire.dao.RedisDao">
<constructor-argindex="0"ref="jedisConfig"/>
<constructor-argindex="1"name="sentinels">
<set>
<value>172.0.0.1:26379</value>
<value>172.0.0.1:26479</value>
<value>172.0.0.1:26579</value>
</set>
</constructor-arg>
</bean>
——删除index="1"后面的<bean id="redisDao" class="com.aspire.dao.RedisDao">
<constructor-arg index="0" ref="jedisConfig" />
<constructor-arg index="1">
<set>
<value>172.0.0.1:26379</value>
<value>172.0.0.1:26479</value>
<value>172.0.0.1:26579</value>
</set>
</constructor-arg>
</bean>
其他原因解决办法:
解决方法:你的XML文件中的配置出错了,可能是某个单词,可能是某个符号写错了,还有就是你的数据表的主键是自动生成的,那么应该这样写:比如插入数据:
开始的时候配置
<mappers>
<mapper resource="classpath:mapper/UserMapper.xml"/>
</mappers>时,启动一直报上面的错
后来将classpath去掉就好了
<mappers><mapper resource="mapper/UserMapper.xml"/>
</mappers>
-----------------------------------
<!-- 配置数据源 -->
<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
改为:
<!-- 配置数据源 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
default-autowire="byType" 改成 default-autowire="byName"
---------------------------------------------------------
[解决办法]
[解决办法]
注入bean类型不匹配
- org.springframework.beans.factory.UnsatisfiedDependencyException异常
- org.springframework.beans.factory.UnsatisfiedDependencyException异常
- 异常org.springframework.beans.factory.UnsatisfiedDependencyException
- org.springframework.beans.factory.UnsatisfiedDependencyException
- org.springframework.beans.factory.UnsatisfiedDependencyException
- org.springframework.beans.factory.UnsatisfiedDependencyException
- 关于Spring中org.springframework.beans.factory.UnsatisfiedDependencyException异常
- Spring中org.springframework.beans.factory.UnsatisfiedDependencyException异常
- spring + redis + org.springframework.beans.factory.UnsatisfiedDependencyException:
- Spring使用@scope("session")爆org.springframework.beans.factory.UnsatisfiedDependencyException
- org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
- Context initialization failed org.springframework.beans.factory.UnsatisfiedDependencyException: Erro
- 异常处理 org.springframework.beans.factory.BeanCreationException
- 异常:org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor
- 异常org.springframework.beans.factory.NoSuchBeanDefinitionException
- org.springframework.beans.factory.BeanCreationException异常
- org.springframework.beans.factory.NoSuchBeanDefinitionException: 异常处理
- org.springframework.beans.factory.NoUniqueBeanDefinitionException异常问题
- 让PIP源使用国内镜像,提升下载速度和安装成功率
- 股票入门基础知识26:销售现金比率——现金流良好情况
- 0. 设计模式概述
- 二、VMware虚拟机下Ubuntu网络配置(NET模式)
- 使用@SpringBootApplication注解
- org.springframework.beans.factory.UnsatisfiedDependencyException异常
- django nginx 单域名 多站点 sessionid 冲突问题
- ubuntu linux 安装 jdk8 wget curl
- Java集合元素ArrayList删除某一项问题及ArrayList总结归纳
- apache 配置虚拟主机后不能使用localhost(127.0.0.1)
- 使用jsp作为视图模板&常规部署
- [OpenCV] 基于聚类的视频关键帧提取
- 20.命名规范
- 泛型