今天在整一个spring的ioc学习demo,碰到一个问题,居然@Autowire在set方法注入map时,map的key类型不能为String之外的其他类型,具体看下面问题
[java]
@Autowired
public void setTypeMap(Map
this.typeMap = typeMap;
}
@Autowired
public void setTypeMap(Map
this.typeMap = typeMap;
}
xml注入配置,即时在map上加上key和value的类型也不行。
[java]
报错:
[java]
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springweb.service.impl.HelloServiceImpl.setTypeMap(java.util.Map); nested exception is org.springframework.beans.FatalBeanException: Key type [class java.lang.Integer] of map [java.util.Map] must be assignable to [java.lang.String]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:589)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
... 13 more
Caused by: org.springframework.beans.FatalBeanException: Key type [class java.lang.Integer] of map [java.util.Map] must be assignable to [java.lang.String]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:761)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:547)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springweb.service.impl.HelloServiceImpl.setTypeMap(java.util.Map); nested exception is org.springframework.beans.FatalBeanException: Key type [class java.lang.Integer] of map [java.util.Map] must be assignable to [java.lang.String]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:589)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
... 13 more
Caused by: org.springframework.beans.FatalBeanException: Key type [class java.lang.Integer] of map [java.util.Map] must be assignable to [java.lang.String]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:761)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at or