gpt4 book ai didi

java - Spring中的HashMap

转载 作者:行者123 更新时间:2023-12-01 11:04:51 26 4
gpt4 key购买 nike

我正在尝试使用 Spring 将键/值添加到 HashMap 中,如下所示:

<bean id="genPhrase" class="com.WheelOfFortune.Client.generatePhrase">
<property name="WordsAndPhrasesLevelOne">
<util:map map-class="java.util.HashMap">
<entry key="Object Oriented Design" value-ref="Process of planning a system of interacting objects for the purpose of solving a software problem, It is one approach to software design." />
<entry key="Hardware devices" value-ref="Collection of physical elements that comprise a computer system." />
<entry key="Operating System" value-ref="A set of programs that manage computer hardware resources and provide common services for application software." />
<entry key="while statement" value-ref="A control flow statement that allows code to be executed repeatedly based on a given boolean condition." />
<entry key="printf statement" value-ref="Refers to a control parameter used by a class of functions typically associated with some types of programming languages." />
<entry key="Internet Service Provider" value-ref="An organization that provides access to the Internet." />
<entry key="round robin" value-ref="Used to describe a document signed by multiple parties in a circle to make it more difficult to determine the order in which it was signed, thus preventing a ringleader from being identified." />
<entry key="Internet Protocol" value-ref="Principal communications protocol used for relaying datagrams (also known as network packets) across an internetwork using the Internet Protocol Suite." />
</util:map>

不太确定我做错了什么,但是当我运行代码时,我得到:

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'genPhrase' defined in file [/home/ryan/workspace/WheelOfFortuneSpring/generatePhrase.xml]: Cannot create inner bean 'util:map#a6d006c' of type [org.springframework.beans.factory.config.MapFactoryBean] while setting bean property 'WordsAndPhrasesLevelOne'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'util:map#a6d006c': Cannot resolve reference to bean 'Process of planning a system of interacting objects for the purpose of solving a software problem, It is one approach to software design.' while setting bean property 'sourceMap' with key [TypedStringValue: value [Object Oriented Design], target type [null]]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'Process of planning a system of interacting objects for the purpose of solving a software problem, It is one approach to software design.' is defined

最后是我的代码:

public class generatePhrase implements generatePhraseInterface {
public void readPhrase() {
for (String key : WordsAndPhrasesLevelOne.keySet())
{
System.out.print(key + " : ");
}
}
private Map<String,String> WordsAndPhrasesLevelOne;

public void setWordsAndPhrasesLevelOne(Map<String,String> WordsAndPhrasesLevelOne)
{
this.WordsAndPhrasesLevelOne = WordsAndPhrasesLevelOne;
}

有人可以建议什么可能导致此异常吗?

最佳答案

value-ref 属性用于引用另一个 bean。相反,请使用 value=。 。 . 在您的条目中,如下所示。

        <entry key="Object Oriented Design" value="Process of planning a system of interacting objects for the purpose of solving a software problem, It is one approach to software design." />

这里的赠品是错误消息的最后一点:

Cannot resolve reference to bean 'Process of planning a system of interacting objects for the purpose of solving a software problem, It is one approach to software design.' while setting bean property 'sourceMap' with key [TypedStringValue: value [Object Oriented Design], target type [null]]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'Process of planning a system of interacting objects for the purpose of solving a software problem, It is one approach to software design.' is defined

关于java - Spring中的HashMap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33056744/

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