Defining enumerated maps in Spring beans

I am trying to define an enum map in my Spring beans xml and I want it to be populated in the xml, however when I try to define it like this

<bean class = "java.util.EnumMap">
    <constructor-arg>
        <util:map key-type="org.itemlist.products.stockitem">
            <entry key="stockitem.SOAP">100</entry>
        </util:map> 
    </constructor-arg>

      

UPDATE

Here is my beans config

<?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:util="http://www.springframework.org/schema/util"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-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">


    <bean class = "java.util.EnumMap">
        <constructor-arg>
            <util:map key-type="org.itemlist.products.stockitem">
                <entry key="stockitem.SOAP">100</entry>
            </util:map> 
        </constructor-arg>
    </bean>

</beans>

      

When I add a value inside a record it is now an error

cvc-complex-type.2.3: Element 'entry' cannot have character [children], because the type content type is element-only.

      

+3


source to share


2 answers


Will you define this schema in the title:

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

      



And the namespace:

xmlns:util="http://www.springframework.org/schema/util"

      

+4


source


This error message means that the item entry

must be empty, i.e. contain text or other elements. The syntax you want is:

<entry key="stockitem.SOAP" value="100"/>

      

The element entry

also allows you to pass a reference to another bean as a value, for example:



<entry key="stockitem.SOAP" value-ref="myOtherBean"/>

      

(which is useless in your situation, I just mentioned it for completeness)

0


source







All Articles