Question

Im trying to create a bean configuration file for my SettingsDto class:

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;

But Im having issues with how Im doing the 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>

The error I get is

Invalid content was found starting with element 'util:map'. No child element is expected at this point

Was it helpful?

Solution

You cannot set value to util:map that way. value can only take a string. Define a util:map separately, then use ref to reference it.

For example:

<util:map id="myMap">
  <entry key="name" value="..." />
</util:map>

<util:list>
  <ref bean="myMap"/>
</util:list>

Also, value-ref should reference another bean - currently you have it as a string literal value, which you can simply use value for.

OTHER TIPS

Maybe it's your beans schema. You have it slightly wrong. It should be:

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

so in the end there were a few issues.

first off my declaration was wrong

    <entry key="phone" value-ref="International" />

needed to be

    <entry key="phone" value="International" />

(no "-ref")

I also changed the xml to define my list and map outside of the bean then referenced it in the bean

    <property name="supportPhones" ref="supportPhoneList" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top