我正在創建一個基於Spring的Scala項目。我的一個物體需要注入一個簡單的Map[String, String]
。我有以下代碼:爲什麼這個Spring映射不能注入到我的Scala對象中?
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:device="http://www.springframework.org/schema/mobile/device"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/mobile/device http://www.springframework.org/schema/mobile/device/spring-mobile-device-1.0.xsd">
<util:map id="validHosts">
<entry key="host1.domain.com" value="queue-1" />
<entry key="host2.domain.com" value="queue-2" />
</util:map>
</beans>
HostMapper.Scala
import scala.collection.JavaConversions._
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
@Component
class HostMapper() {
@Autowired private var validHosts:java.util.Map[String, String] = null
}
當運行這個程序,我啓動時獲取以下錯誤:
org.springframework.beans.factory .NoSuchBeanDefinitionException:找不到匹配[java.lang.String]類型的匹配bean,用於依賴性[值類型爲java.lang.String的映射]:預期的a至少有1個bean符合此依賴關係的自動導向候選。
我試圖明確聲明鍵和值類型爲java.lang.String
,但這沒有效果。任何想法我可能做錯了什麼?
嘗試放置二傳手? – pedrofurla 2012-08-15 03:14:08