[英]Spring bean configuration list<map>
我試圖為我的SettingsDto
類創建一個bean配置文件:
public class SettingsDto {
private String administratorEmail;
private String gatekeeperAddress;
private String webRtcUrl;
private String userGuideUrl;
private String vmrFaqUrl;
private String lyncGuideUrl;
List<Map<String, String>> supportPhones;
List<String> audioCalls;
但我遇到了如何使用supportPhones( List<Map<String, String>>
)的問題
<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<context:component-scan base-package="sandbox.spring" />
<bean id="SettingsBean" class="com.dto.SettingsDto">
<property name="administratorEmail" value="v@.com" />
<property name="gatekeeperAddress" value="192.168.1.0" />
<property name="webRtcUrl" value="https://web.com" />
<property name="userGuideUrl"
value="url" />
<property name="vmrFaqUrl"
value="url" />
<property name="lyncGuideUrl"
value="url" />
<property name="audioCalls">
<util:list>
<value>+1 (000)000-0000</value>
<value>(000)000-0000</value>
</util:list>
</property>
<property name="supportPhones">
<util:list>
<ref bean="supportPhonesMapping1" />
<ref bean="supportPhonesMapping2" />
</util:list>
</property>
<util:map id="supportPhonesMapping1">
<entry key="name" value="North America" />
<entry key="phone" value-ref="+1 111-1111" />
</util:map>
<util:map id="supportPhonesMapping2">
<entry key="name" value="+11 111-1111" />
<entry key="phone" value-ref="International" />
</util:map>
</bean>
</beans>
我得到的錯誤是
找到以元素'util:map'開頭的無效內容。 此時不會有子元素
你不能將值設置為util:map
那樣。 value
只能取一個字符串。 分別定義一個util:map
,然后使用ref
引用它。
例如:
<util:map id="myMap">
<entry key="name" value="..." />
</util:map>
<util:list>
<ref bean="myMap"/>
</util:list>
此外, value-ref
應引用另一個bean - 目前您將其作為字符串文字值,您可以簡單地使用value
。
也許這是你的bean架構。 你有點錯誤。 它應該是:
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
所以最后還是有一些問題。
首先,我的聲明是錯的
<entry key="phone" value-ref="International" />
需要
<entry key="phone" value="International" />
(沒有“-ref”)
我還更改了xml以定義我的列表並在bean之外映射然后在bean中引用它
<property name="supportPhones" ref="supportPhoneList" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.