我正在创建一个基于 Spring 的 Scala 项目。我的一个对象需要一个简单的Map[String, String]
注入。我有以下代码:
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 [map with value type java.lang.String]:预计至少有 1 个 bean 有资格作为此依赖项的自动装配候选者.
我尝试将键和值类型明确声明为java.lang.String
,但这没有效果。有什么想法我可能做错了吗?