1
votes

I'm trying to use Spring and have a trouble using it for a case. I have the following code:

<util:map id="someMap" value-type="java.util.Set">
    <entry key="a" value-ref="setA"/>
    <entry key="b" value-ref="setB"/>
</util:map>

<util:set id="setA">
    <value>A</value>
</util:set>

<util:set id="setB">
    <value>B</value>
</util:set>

with the following Java code (using @Qualifier to get "someMap"):

package a.b.c;
public class SomeClass {
    private final Map<String, Set<String>> someMap;
    @Autowired
    public SomeClass(@Qualifier("someMap") final Map<String, Set<String>> someMap) {
        this.someMap = someMap;
    }
}

and it's giving me the following error:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'a.b.c.SomeClass': Unsatisfied dependency expressed through constructor argument with index 2 of type [java.util.Map]: : No matching bean of type [java.util.Set] found for dependency [map with value type java.util.Set]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations:{@org.springframework.beans.factory.annotation.Qualifier(value=someMap)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [java.util.Set] found for dependency [map with value type java.util.Set]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Qualifier(value=someMap)}

Looks like it's having trouble finding the Set but I don't know why it's happening. How would you solve this problem?

2
Are u using spring 4.3 or above version.lower Spring version, you can't autowire a collectionAssenKhan

2 Answers

0
votes

I found how to fix this issue. I had to use @Value("#{@someMap}") instead of @Qualifier("someMap").

0
votes

I hope you are using spring 4.3 or above version Try with adding mapclass,key-type

<util:map id="AdditionalParams" map-class="java.util.HashMap" 
          key-type="java.lang.String" value-type="java.lang.String">