J'essaie d'utiliser Spring et j'ai du mal à l'utiliser pour un cas. Je le code suivant:Injection de dépendances avec Spring ne fonctionnant pas lors de l'utilisation de beans imbriqués
<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>
avec le code Java suivant (en utilisant @Qualifier pour obtenir "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;
}
}
et il me donne l'erreur suivante:
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)}
On dirait qu'il a du mal à trouver le Set mais je ne sais pas pourquoi ça se passe. comment résoudrais-tu ce problème?
Utilisez-vous spring 4.3 ou plus version.lower Version printemps, vous ne pouvez pas autowire une collection – Assen