org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'name' defined in class path resource [test/appcontext/string-prototype.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.lang.String]: Illegal arguments for constructor; nested exception is java.lang.IllegalArgumentException: argument type mismatch

Spring JIRA | Thomas Biskup | 8 years ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    I happened to stumble upon a strange prototype instantiation behaviour which I could narrow down to the following example: AppContext: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="name" class="java.lang.String" scope="prototype"> <constructor-arg value="Willy"/> </bean> </beans> Example class: package test.appcontext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class ClassPathAppContextMain { public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("test/appcontext/string-prototype.xml"); String n1 = (String) context.getBean("name"); String n2 = (String) context.getBean("name"); } } Starting the example leads to the following crash: Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'name' defined in class path resource [test/appcontext/string-prototype.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.lang.String]: Illegal arguments for constructor; nested exception is java.lang.IllegalArgumentException: argument type mismatch at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:254) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:823) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:283) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:880) at test.appcontext.ClassPathAppContextMain.main(ClassPathAppContextMain.java:10) Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.lang.String]: Illegal arguments for constructor; nested exception is java.lang.IllegalArgumentException: argument type mismatch at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:111) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:248) ... 11 more Caused by: java.lang.IllegalArgumentException: argument type mismatch at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100) ... 13 more When you remove the 'scope="prototype"' attribute in the app context definition, the sample works. What is the problem with the prototype scope and constructor based instantiation?

    Spring JIRA | 8 years ago | Thomas Biskup
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'name' defined in class path resource [test/appcontext/string-prototype.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.lang.String]: Illegal arguments for constructor; nested exception is java.lang.IllegalArgumentException: argument type mismatch
  2. 0

    I happened to stumble upon a strange prototype instantiation behaviour which I could narrow down to the following example: AppContext: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="name" class="java.lang.String" scope="prototype"> <constructor-arg value="Willy"/> </bean> </beans> Example class: package test.appcontext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class ClassPathAppContextMain { public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("test/appcontext/string-prototype.xml"); String n1 = (String) context.getBean("name"); String n2 = (String) context.getBean("name"); } } Starting the example leads to the following crash: Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'name' defined in class path resource [test/appcontext/string-prototype.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.lang.String]: Illegal arguments for constructor; nested exception is java.lang.IllegalArgumentException: argument type mismatch at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:254) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:823) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409) at java.security.AccessController.doPrivileged(Native Method) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:283) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:880) at test.appcontext.ClassPathAppContextMain.main(ClassPathAppContextMain.java:10) Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.lang.String]: Illegal arguments for constructor; nested exception is java.lang.IllegalArgumentException: argument type mismatch at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:111) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:248) ... 11 more Caused by: java.lang.IllegalArgumentException: argument type mismatch at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100) ... 13 more When you remove the 'scope="prototype"' attribute in the app context definition, the sample works. What is the problem with the prototype scope and constructor based instantiation?

    Spring JIRA | 8 years ago | Thomas Biskup
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'name' defined in class path resource [test/appcontext/string-prototype.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.lang.String]: Illegal arguments for constructor; nested exception is java.lang.IllegalArgumentException: argument type mismatch
  3. 0

    Different types returned for production code (Oracle) and in integration tests (HSQLDB)

    GitHub | 4 years ago | perkoren
    java.lang.IllegalArgumentException: argument type mismatch
  4. Speed up your debug routine!

    Automated exception search integrated into your IDE

  5. 0

    Java newInstance passing args[1]...args[args.length]

    Stack Overflow | 3 years ago | user3343917
    java.lang.IllegalArgumentException: argument type mismatch
  6. 0

    Can't deploy an application twice using Glassfish Embedded v3.1

    Stack Overflow | 6 years ago | Thiago Negri
    org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: javax.servlet.ServletException: com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class com.senior.seguranca.csmcenter.CsmCenterContextListener

  1. derprogger 4 times, last 3 weeks ago
  2. Pilleo 1 times, last 1 month ago
  3. arturgajowy 12 times, last 1 month ago
  4. johnxfly 1 times, last 1 month ago
  5. Dunmer 63 times, last 2 months ago
4 more registered users
17 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. java.lang.IllegalArgumentException

    argument type mismatch

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0()
  2. Java RT
    Constructor.newInstance
    1. sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    2. sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    3. sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    4. java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    4 frames
  3. Spring Beans
    AbstractAutowireCapableBeanFactory$1.run
    1. org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)
    2. org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)
    3. org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:248)
    4. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)
    5. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:823)
    6. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
    7. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    7 frames
  4. Java RT
    AccessController.doPrivileged
    1. java.security.AccessController.doPrivileged(Native Method)
    1 frame
  5. Spring Beans
    AbstractBeanFactory.getBean
    1. org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    2. org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:283)
    3. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    4. org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    4 frames
  6. Spring Context
    AbstractApplicationContext.getBean
    1. org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:880)
    1 frame
  7. test.appcontext
    ClassPathAppContextMain.main
    1. test.appcontext.ClassPathAppContextMain.main(ClassPathAppContextMain.java:10)
    1 frame