解决程序中Error creating bean with name 'XXXXX‘ defined in class path resource 的异常
可以说是一个较为低级的错误:Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘xx’ defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type ‘java.util.LinkedHashMap’ to required type ‘java.util.Map’ for property ‘mapRoleUser’; nested exception is java.lang.IllegalStateException: Cannot convert value of type ‘java.lang.String’ to required type ‘it.com.UserInfo’ for property ‘mapRoleUser[it.com.Role@6ec8211c]’: no matching editors or conversion strategy found
Exception in thread “main” org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘xx’ defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type ‘java.util.LinkedHashMap’ to required type ‘java.util.Map’ for property ‘mapRoleUser’; nested exception is java.lang.Illega
到这里我们就可以明确的知道datasource配置肯定有误,因此我们要去检查我们在applicationContext.xml文件中配置的数据源,
我们应该写成:
第二种:
应该把上面一句中的value改成了ref,如下:
ref和value区别:value对应的是给属性赋值是基本数据类型和string类型的。ref是对应的当前xml文件中配置过的bean类型。