spring 配置xml注入bean同名异常的问题

应用环境:使用了struts2、spring2.5和ibatis等。

问题重现:xml配置文件如下,

	<bean id="logAction" class="packageName.LogAction" scope="prototype">
		<property name="logManager" ref="logManager"/>
	</bean>
	<bean id="logManager" class="packageName.LogManagerImpl" scope="prototype">
		<property name="logDao" ref="logDao"/>	
	</bean>
	
	<bean id="logDao" class="packageName.LogDaoiBatis" scope="prototype">
		<property name="sqlMapClient" ref="sqlMapClient"/>	
	</bean>

由于整个项目中有很多spring配置文件,这里的logManager 在别的地方也有配置,且指定的另外的一个类,在应用启动的时候,还没有报错(我想spring 只是检查,没有真正注入吧,还是有相关配置?),在用到该模块的时候,会报如下错误(大概意思是logAction无法为logManager这个属性注入bean):

Unable to instantiate Action, logAction,  defined for 'queryLogs' in namespace 'ExampleNamespace'Error creating bean with name 'logAction' defined in ServletContext resource beanA.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy6] to required type [packageName.log.LogManager] for property 'logManager'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy6] to required type [packageName.log.LogManager] for property 'logManager': no matching editors or conversion strategy found - action - file:/F:/path/strutsConf.xml:9:71

 ps:有些命名空间和文件名做了修改。strutsConf.xml某个模块的struts配置文件。

 

 

用下面配置方式就解决了重名的问题:

<bean id="logAction" class="packageName.LogAction" scope="prototype">
		<property name="logManager">
			<bean class="packageName.log.LogManagerImpl">
				<property name="logDao">
					<bean  class="packageName.log.LogDaoiBatis" scope="prototype">
						<property name="sqlMapClient" ref="sqlMapClient"/>	
					</bean>
				</property>
			</bean>
		</property>	
	</bean>

 

只做个记录,研究的比较浅,有了解的请指教,呵呵 O(∩_∩)O~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值