Hi experts,
Is there a working example-xml-snippet wich shows correct usage of a Map<java.util.Class,xxx> bean-definition?
should be mapped toCode:<util:map id="myMap" key-type="java.lang.Class" value-type="java.lang.String"> <entry key="java.lang.String" value="Hallo"></entry> </util:map>
I always get the Exception:Code:@Autowired @Qualifier("myMap") Map<java.util.Class,java.lang.String>
I checked the spring-source-code at DefaultListableBeanFactory.resolveDependency(Defau ltListableBeanFactory.java:585).Code:org.springframework.beans.FatalBeanException: Key type [class java.lang.Class] of map [java.util.Map] must be assignable to [java.lang.String] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:435) at org.springframework.beans.factory.annotation.InjectionMetadata.injectFields(InjectionMetadata.java:105) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessAfterInstantiation(AutowiredAnnotationBeanPostProcessor.java:240) ... 27 more Caused by: org.springframework.beans.FatalBeanException: Key type [class java.lang.Class] of map [java.util.Map] must be assignable to [java.lang.String] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:585) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:412) ... 29 more
but it seams that mapping a key-type of java.util.Class will never work sinceCode:Class keyType = descriptor.getMapKeyType(); if (keyType == null || !String.class.isAssignableFrom(keyType)) {
evaluates to 'false'Code:String.class.isAssignableFrom( Class.class )


Reply With Quote