org.springframework.beans.factory.UnsatisfiedDependencyException异常
2017-01-06 11:22
671 查看
关于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"后面的name="sentinels"问题解决。
<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文件中的配置出错了,可能是某个单词,可能是某个符号写错了,还有就是你的数据表的主键是自动生成的,那么应该这样写:比如插入数据:
<insertid="insertUser" parameterType="com.myschool.entity.UserInfo"useGeneratedKeys="true" keyProperty="userId">
insert into userinfo(userName,userPassword)values(#{userName},#{userPassword})
</insert>
--------------------------------
开始的时候配置
<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 id="userService" class="com.service.impl.ServiceImpl">
<!-- <property name="userDao" ref="userDao"></property> -->
<constructor-arg value="userDao" />
</bean>
[解决办法]
注入bean类型不匹配
相关文章推荐
- org.springframework.beans.factory.UnsatisfiedDependencyException异常
- springboot Junittest 报异常:org.springframework.beans.factory.UnsatisfiedDependencyException:
- 关于Spring中org.springframework.beans.factory.UnsatisfiedDependencyException异常
- org.springframework.beans.factory.UnsatisfiedDependencyException 异常这么解决
- SSM中关于service中mapper注入失败org.springframework.beans.factory.UnsatisfiedDependencyException: Error crea
- org.springframework.beans.factory.UnsatisfiedDependencyException
- Spring使用@scope("session")爆org.springframework.beans.factory.UnsatisfiedDependencyException
- org.springframework.beans.factory.UnsatisfiedDependencyException
- spring + redis + org.springframework.beans.factory.UnsatisfiedDependencyException:
- 启动项目报错:org.springframework.beans.factory.UnsatisfiedDependencyException
- org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name'se
- Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean wi
- org.springframework.beans.factory.UnsatisfiedDependencyException
- org.springframework.beans.factory.UnsatisfiedDependencyException
- org.springframework.beans.factory.UnsatisfiedDependencyException
- org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
- org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com
- SpringMvc常见异常之org.springframework.beans.factory.NoSuchBeanDefinitionException
- org.springframework.beans.factory.NoSuchBeanDefinitionException: 异常处理
- 题目:org.springframework.beans.factory.BeanCreationException(hibernate中的jar包和spring中的jar包冲突)异常产生的原因和解决方案。