spring配置文件的注入问题

insert_viann 2011-10-11 03:12:18
求解:
这样写的时候没有错
<bean id="organuserServices"
class="com.dianxue.services.impl.OrganuserServices">
<property name="entityDao">
<ref bean="organuserDAO"/>
</property>
</bean>


这样写报错了:
	<bean id="organuserServices"
class="com.dianxue.services.impl.OrganuserServices">
<property name="entityDao">
<list>
<ref bean="organuserDAO"/>
</list>
</property>
</bean>


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'organuserServices' defined in ServletContext resource [/WEB-INF/classes/dataAccessContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.util.ArrayList] to required type [com.core.DAO.EntityDao] for property 'entityDao'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [java.util.ArrayList] to required type [com.core.DAO.EntityDao] for property 'entityDao': no matching editors or conversion strategy found
...全文
166 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
insert_viann 2011-10-11
  • 打赏
  • 举报
回复
问题解决了 结贴
dragonisgod 2011-10-11
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 zhouyuqwert 的回复:]

引用 11 楼 insert_viann 的回复:

引用 9 楼 zhouyuqwert 的回复:




可是把参数改成list的话, entityDao 就变成list类型了,就不能entityDao.selectByID 这样调用了

怎么安排都是逻辑上来说的,我只是说你如果要用<list></list>那你set的参数必须是List<>来匹配
业务逻辑如果需要你用……
[/Quote]12L正解
阳明 to life 2011-10-11
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 insert_viann 的回复:]

引用 9 楼 zhouyuqwert 的回复:




可是把参数改成list的话, entityDao 就变成list类型了,就不能entityDao.selectByID 这样调用了
[/Quote]
怎么安排都是逻辑上来说的,我只是说你如果要用<list></list>那你set的参数必须是List<>来匹配
业务逻辑如果需要你用list 你就用List 然后需要用到的时候从List里面取出某个元素再调用方法
如果逻辑上不是list你就不要用list了
insert_viann 2011-10-11
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 zhouyuqwert 的回复:]


[/Quote]

可是把参数改成list的话, entityDao 就变成list类型了,就不能entityDao.selectByID 这样调用了
livesguan 2011-10-11
  • 打赏
  • 举报
回复
查一个spring <list></list> 标签用法.....
阳明 to life 2011-10-11
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 insert_viann 的回复:]

Java code

public void setEntityDao(EntityDao entityDao) {
this.entityDao = entityDao;
}



那是不是把setEntityDao的参数改成list呢
[/Quote]
insert_viann 2011-10-11
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 zhongxingxuan 的回复:]
可是我想把两个dao 都注入到 entityDao属性 中
insert_viann 2011-10-11
  • 打赏
  • 举报
回复

public void setEntityDao(EntityDao entityDao) {
this.entityDao = entityDao;
}


那是不是把setEntityDao的参数改成list呢
仲兴轩 2011-10-11
  • 打赏
  • 举报
回复

<bean id="organuserServices"
class="com.dianxue.services.impl.OrganuserServices">
<property name="entityDao">
<ref bean="organuserDAO"/>
</property>
<property name="第二个Dao">
<ref bean="第二个Dao"/>
</property>
</bean>

阳明 to life 2011-10-11
  • 打赏
  • 举报
回复
噢。。。看错了
<list>
<ref bean="organuserDAO"/>
</list>
这个就是List类型
阳明 to life 2011-10-11
  • 打赏
  • 举报
回复
setEntityDao参数呢 是什么类型
insert_viann 2011-10-11
  • 打赏
  • 举报
回复

<bean id="organuserDAO" class="com.dianxue.dao.impl.OrganuserDAO"
<property name="sqlMapClient" ref="sqlMapClient" />
</bean>


这就是那个bean bean怎么会是ArrayList类型呢
阳明 to life 2011-10-11
  • 打赏
  • 举报
回复
Cannot convert value of type [java.util.ArrayList] to required type [com.core.DAO.EntityDao] for property 'entityDao'
类型转换异常 organuserDAO这个BEAN是ArrayList?
insert_viann 2011-10-11
  • 打赏
  • 举报
回复
我是需要加list的,因为我想给那个属性注入两个dao的

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧