2
我看到下面的錯誤,它試圖將一個映射注入到一個bean中。我不確定Spring是如何推斷我試圖注入的映射是org.apache.commons.collections.map.LinkedMap類型的。我該如何解決這個問題?彈簧注入映射問題
[org.apache.commons.collections.map.LinkedMap]所需類型 [java.util.LinkedHashMap中用於屬性 'asyncConnectorDaoMap';嵌套0例外是java.lang.IllegalArgumentException異常:不能類型的值轉換 [org.apache.commons.collections.map.LinkedMap]所需 類型[java.util.LinkedHashMap中]
Spring配置
<bean id="fulfillment.management.AsyncConnectorFactory" class="com.service.async.AsyncConnectorFactory"> <property name="asyncConnectorDaoMap"> <map key-type="java.lang.String" value-type="com.service.async.AsyncConnectorDao">
<entry key="ACCOUNT_MANAGEMENT_CONTROLLER" value-ref="core.commons.AsyncConnectorDao"></entry>
<entry key="CUSTOMER_SERVICE" value-ref="core.commons.AsyncConnectorDao"></entry>
<entry key="ACCOUNT_SERVICE" value-ref="core.commons.AsyncConnectorDao"></entry>
<entry key="LOCATION_SERVICE" value-ref="core.commons.AsyncConnectorDao"></entry> </map> </property> </bean>
下面的代碼
import java.util.LinkedHashMap;
public class AsyncConnectorFactory {
private LinkedHashMap<String, AsyncConnectorDao> asyncConnectorDaoMap;
public LinkedHashMap<String, AsyncConnectorDao> getAsyncConnectorDaoMap() {
return asyncConnectorDaoMap;
}
public void setAsyncConnectorDaoMap(
LinkedHashMap<String, AsyncConnectorDao> asyncConnectorDaoMap) {
this.asyncConnectorDaoMap = asyncConnectorDaoMap;
}
public AsyncConnectorDao getAsyncConcurrentConnectorDao(String serviceIdentifier) {
return asyncConnectorDaoMap.get(serviceIdentifier);
}
}
修改工作配置
<bean id="fulfillment.management.AsyncConnectorFactory" class="com.service.async.AsyncConnectorFactory">
<property name="asyncConnectorDaoMap" ref="asyncConnectorDaoMap1"/>
</bean>
<util:map id="asyncConnectorDaoMap1" map-class="java.util.LinkedHashMap">
<entry key="ACCOUNT_MANAGEMENT_CONTROLLER" value-ref="core.commons.AsyncConnectorDao"></entry>
<entry key="CUSTOMER_SERVICE" value-ref="core.commons.AsyncConnectorDao"></entry>
<entry key="ACCOUNT_SERVICE" value-ref="core.commons.AsyncConnectorDao"></entry>
<entry key="LOCATION_SERVICE" value-ref="core.commons.AsyncConnectorDao"></entry>
謝謝Koitoer的,是有什麼問題我已經定義的方式嗎? –
我認爲問題在於value-ref,似乎是指向一個類而不是一個bean – Koitoer
謝謝Kotoer,現在就開始工作。我粘貼了工作配置。 –