Note that there are some explanatory texts on larger screens.

plurals
  1. POutil:map in Spring picking up every bean of the map type
    primarykey
    data
    text
    <p>I have a Spring map problem that is bringing me to tears.</p> <p>My spring looks like this:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd "&gt; &lt;util:map id="mockMap"&gt; &lt;entry key="userTest1" value="test1"/&gt; &lt;entry key="userTest2" value="test2"/&gt; &lt;entry key="userTest3" value="test6"/&gt; &lt;/util:map&gt; &lt;/beans&gt; </code></pre> <p>Then the code where I am autowiring this is as follows (irrelevant parts ommitted):</p> <pre><code>@Autowired @Resource(name="mockMap") Map&lt;String, String&gt; testMap; @Test public void testGetGearListActivityOK() { for (String key : testMap.keySet()) { System.out.println("key = " + key); } } </code></pre> <p>Amazingly enough, this will actually give me an error on the autowiring step saying that there are no beans matching type String. However, if I change the map in the unit-test to be defined as Map then I get the follow output:</p> <blockquote> <pre><code>[junit] key = mockMap [junit] key = org.springframework.context.annotation.internalConfigurationAnnotationProcessor [junit] key = org.springframework.context.annotation.internalAutowiredAnnotationProcessor [junit] key = org.springframework.context.annotation.internalRequiredAnnotationProcessor [junit] key = org.springframework.context.annotation.internalCommonAnnotationProcessor [junit] key = systemProperties [junit] key = systemEnvironment [junit] key = messageSource [junit] key = applicationEventMulticaster [junit] key = lifecycleProcessor </code></pre> </blockquote> <p>I have not yet been able to get the key section of the entry to actually show up as a key. If I change the map back to Map and add some into my spring then the map populates with those, using their id's as the keys.</p> <p>I'm so confused here and have used spring a decent amount in the past. If anyone has a clue what the heck is going on here I'd be very grateful.</p> <p>Thanks in advance.</p> <p>Also, I saw this question: <a href="https://stackoverflow.com/questions/1363310/auto-wiring-a-list-using-util-schema-gives-nosuchbeandefinitionexception">Auto-wiring a List using util schema gives NoSuchBeanDefinitionException</a></p> <p>But the solution there is to use @Resource, which I am already doing..</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload