org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityModel' defined in class path resource [applicationContext-siteresources.xml]: Initialization of bean failed; nested exception is java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String

Spring JIRA | Marvel | 8 years ago
  1. 0

    This is the worst possible kind of bug report, and so I apologize in advance, but it has only appeared once in production and was not reproducible. On top of that, the actual case that generates the error seems to be pretty much impossible. The cast exception you see below, is in this Spring code: /** * Return the class name of the wrapped bean. */ public String getBeanClassName() { if (this.beanClass instanceof Class) { return ((Class) this.beanClass).getName(); } else { return (String) this.beanClass; } } As you can see the method checks if the field is a Class, and casts to it if it is. However, in this case below, for some reason, it tried to cast it to a String even though it was a Class. I don't know if this is some strange classloading issue, a JVM bug, or what, but I figured you would want to at least see it. Stack trace: ------------------------------ org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityModel' defined in class path resource [applicationContext-siteresources.xml]: Initialization of bean failed; nested exception is java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String at org.springframework.beans.factory.support.AbstractBeanDefinition.getBeanClassName(AbstractBeanDefinition.java:311) at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:327) at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1066) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:349) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:270) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByName(AbstractAutowireCapableBeanFactory.java:881) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:829) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:424) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:270) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:229) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:733) at com.cargurus.site.interceptor.ModelInterceptor.intercept(ModelInterceptor.java:75)

    Spring JIRA | 8 years ago | Marvel
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityModel' defined in class path resource [applicationContext-siteresources.xml]: Initialization of bean failed; nested exception is java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String
  2. 0

    This is the worst possible kind of bug report, and so I apologize in advance, but it has only appeared once in production and was not reproducible. On top of that, the actual case that generates the error seems to be pretty much impossible. The cast exception you see below, is in this Spring code: /** * Return the class name of the wrapped bean. */ public String getBeanClassName() { if (this.beanClass instanceof Class) { return ((Class) this.beanClass).getName(); } else { return (String) this.beanClass; } } As you can see the method checks if the field is a Class, and casts to it if it is. However, in this case below, for some reason, it tried to cast it to a String even though it was a Class. I don't know if this is some strange classloading issue, a JVM bug, or what, but I figured you would want to at least see it. Stack trace: ------------------------------ org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityModel' defined in class path resource [applicationContext-siteresources.xml]: Initialization of bean failed; nested exception is java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String at org.springframework.beans.factory.support.AbstractBeanDefinition.getBeanClassName(AbstractBeanDefinition.java:311) at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:327) at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1066) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:349) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:270) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByName(AbstractAutowireCapableBeanFactory.java:881) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:829) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:424) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:270) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:229) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:733) at com.cargurus.site.interceptor.ModelInterceptor.intercept(ModelInterceptor.java:75)

    Spring JIRA | 8 years ago | Marvel
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityModel' defined in class path resource [applicationContext-siteresources.xml]: Initialization of bean failed; nested exception is java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String
  3. 0

    [WG: Sakai QA] Trunk is down

    sakaiproject.org | 1 year ago
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.sakaiproject.entitybroker.impl.entityprovider.EntityProviderAutoRegistrar' defined in file [/home/tomcat-nightly/sakai-demo-oracle/components/entitybroker-pack/WEB-INF/components.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.sakaiproject.sitestats.api.report.ReportDefEntityProvider' defined in class path resource [site-stats-components.xml]: Cannot resolve reference to bean 'org.sakaiproject.sitestats.api.report.ReportManager' while setting bean property 'reportManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.sakaiproject.sitestats.api.report.ReportManager' defined in class path resource [site-stats-components.xml]: Cannot resolve reference to bean 'org.sakaiproject.sitestats.api.StatsManager' while setting bean property 'statsManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.sakaiproject.sitestats.api.StatsManager' defined in class path resource [site-stats-components.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'clusterService' of bean class [org.sakaiproject.sitestats.impl.StatsManagerImpl]: Bean property 'clusterService' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Editor / Upload document does not work

    GitHub | 2 years ago | pvgenuchten
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resource.upload.and.link': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private jeeves.server.context.ServiceContext org.fao.geonet.services.resources.UploadAndProcess.context; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [jeeves.server.context.ServiceContext] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  6. 0

    Got following error in running server "java.lang.NoSuchMethodError: java/lang/Object.toString()Ljava/lang/String;"

    Stack Overflow | 3 years ago | Pathik
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myBean5' defined in ServletContext resource [/WEB-INF/v2_0/myApplicationContext.xml]: Cannot resolve reference to bean 'myBean1' while setting bean property 'myProperty3' with key [3]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myBean1' defined in ServletContext resource [/WEB-INF/myApplicationContext.xml]: Cannot resolve reference to bean 'myBean2' while setting bean property 'myProperty4' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myBean2' defined in ServletContext resource [/WEB-INF/myApplicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: java/lang/Object.toString()Ljava/lang/String;

  1. tvrmsmith 2 times, last 3 months ago
  2. abrazeneb 2 times, last 4 months ago
  3. rlovtangen 1 times, last 5 months ago
  4. kjhdofjosvs 3 times, last 4 weeks ago
  5. Tahir 6 times, last 2 months ago
13 more registered users
80 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. org.springframework.beans.factory.BeanCreationException

    Error creating bean with name 'entityModel' defined in class path resource [applicationContext-siteresources.xml]: Initialization of bean failed; nested exception is java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String Caused by: java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.String

    at org.springframework.beans.factory.support.AbstractBeanDefinition.getBeanClassName()
  2. Spring Beans
    AbstractBeanFactory.getBean
    1. org.springframework.beans.factory.support.AbstractBeanDefinition.getBeanClassName(AbstractBeanDefinition.java:311)
    2. org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:327)
    3. org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1066)
    4. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:349)
    5. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:270)
    6. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    7. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByName(AbstractAutowireCapableBeanFactory.java:881)
    8. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:829)
    9. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:424)
    10. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:270)
    11. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:229)
    12. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)
    12 frames
  3. Spring Context
    AbstractApplicationContext.getBean
    1. org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:733)
    1 frame
  4. com.cargurus.site
    ModelInterceptor.intercept
    1. com.cargurus.site.interceptor.ModelInterceptor.intercept(ModelInterceptor.java:75)
    1 frame