org.springframework.beans.factory.BeanCreationException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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)
    via by Marvel,
  • 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)
    via by 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 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)

    Users with the same issue

    treefolk
    1 times, last one,
    tvrmsmith
    2 times, last one,
    abrazeneb
    2 times, last one,
    rlovtangen
    1 times, last one,
    Unknown visitor1 times, last one,
    128 more bugmates