Error Message:
Unable to instantiate Action, trafficAction, defined for ’traffic_index’ in namespace ’/freemarker/traffic’Error creating bean with name ’trafficAction’ defined in URL [file:/F:/kevin/mywork/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/ft_sitestat/WEB-INF/classes/config/spring/application_traffic.xml]: Initialization of bean failed ; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type ’$Proxy27 implementing com.fantong.stat.traffic.chart.line.service.ILineService ,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised’ to required type ’com.fantong.stat.traffic.chart.line.service.LineService’ for property ’lineService’; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy27 implementing com.fantong.stat.traffic.chart.line.service.ILineService, org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.fantong.stat.traffic.chart.line.service.LineService] for property ’lineService’: no matching editors or conversion strategy found
spring 配置中遇到该问题,一般是因为参数注入的原因:例如,我的Spring配置文件里是这样写的:
<bean id=“trafficAction” class=“com.fantong.stat.traffic.action.TrafficAction”
scope=“prototype”>
<property name=“lineService” ref=“traffic_lineService” />
</bean>
<bean id=“traffic_lineAction” class=“com.fantong.stat.traffic.chart.line.action.LineAction”
scope=“prototype”>
<property name=“lineService” ref=“traffic_lineService” />
</bean>
<bean id=“traffic_lineDao” class=“com.fantong.stat.traffic.chart.line.dao.LineDao”></bean>
<bean id=“traffic_lineService” class=“com.fantong.stat.traffic.chart.line.service.LineService”>
<property name=“lineDao” ref=“traffic_lineDao” />
</bean>
由于,com.fantong.stat.traffic.chart.line.service.LineService这个类实际上是实现IlineService接口的,由于Spring注入的是接口,关联的是实现类。 这里注入了实现类,所以报异常了。
解决办法:在Spring的配置文件加上下面代码,注明可以用实现类注入。:
<aop:config proxy-target-class=“true”></aop:config>