gpt4 book ai didi

java - 在 Spring bean 中定义枚举映射

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:19:10 25 4
gpt4 key购买 nike

我试图在我的 Spring bean xml 中定义一个枚举映射,并且我希望它填充到 xml 中,但是当我尝试像这样定义它时

<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配置

<?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>

当我在条目中添加一个值时,这就是现在的错误

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

最佳答案

您是否在 header 中定义了这些模式:

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

和命名空间:

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

关于java - 在 Spring bean 中定义枚举映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14971302/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com