<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=bendredi" rel="nofollow">Endrédi, Balázs</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-5569?redirect=false" rel="nofollow">SPR-5569</a></strong> and commented</p>
<p dir="auto">Bean definition:<br>
&lt;bean id="test" singleton="false" class="java.lang.String"&gt;<br>
&lt;constructor-arg&gt;<br>
&lt;value&gt;test&lt;/value&gt;<br>
&lt;/constructor-arg&gt;<br>
&lt;/bean&gt;</p>
<p dir="auto">code:<br>
Object stringBean1 = ctx.getBean("test")<br>
Object stringBean2 = ctx.getBean("test")</p>
<p dir="auto">The first reading of the bean is ok.<br>
The second reading fails because the system interprets the bean as java.lang.StringBuilder.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0.4, 3.0 M2</p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/15203/StringBean_Mail_Eberhard_Wolff.pdf" rel="nofollow">StringBean_Mail_Eberhard_Wolff.pdf</a> (<em>78.06 kB</em>)</li>
<li><a href="https://jira.spring.io/secure/attachment/15202/TestCaseStringBean.jar" rel="nofollow">TestCaseStringBean.jar</a> (<em>3.91 kB</em>)</li>
</ul>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398104452" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/11744" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/11744/hovercard" href="https://github.com/spring-projects/spring-framework/issues/11744">#11744</a> IllegalArgumentException thrown for simple java.lang.String prototype bean  (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=diwakar" rel="nofollow">diwakar</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7084?redirect=false" rel="nofollow">SPR-7084</a></strong> and commented</p>
<p dir="auto">Code</p>
<hr>
<p dir="auto">import org.springframework.context.support.GenericApplicationContext;<br>
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;<br>
import org.springframework.core.io.ClassPathResource;</p>
<p dir="auto">/**<br>
*/<br>
public class IllegalArgumentProblem {</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="public static void main(String[] args) {
     GenericApplicationContext parent = new GenericApplicationContext();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(parent);
    reader.loadBeanDefinitions(new ClassPathResource(&quot;app.xml&quot;, IllegalArgumentProblem.class));
    parent.refresh();

    String bean = (String) parent.getBean(&quot;x&quot;);
    String bean2 = (String) parent.getBean(&quot;x&quot;); // second access throws the exception.
}"><pre class="notranslate"><code class="notranslate">public static void main(String[] args) {
     GenericApplicationContext parent = new GenericApplicationContext();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(parent);
    reader.loadBeanDefinitions(new ClassPathResource("app.xml", IllegalArgumentProblem.class));
    parent.refresh();

    String bean = (String) parent.getBean("x");
    String bean2 = (String) parent.getBean("x"); // second access throws the exception.
}
</code></pre></div>
<p dir="auto">}</p>
<p dir="auto">Configuration</p>
<hr>
<p dir="auto">&lt;beans xmlns="<a href="http://www.springframework.org/schema/beans" rel="nofollow">http://www.springframework.org/schema/beans</a>"<br>
xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" rel="nofollow">http://www.w3.org/2001/XMLSchema-instance</a>"<br>
xsi:schemaLocation="<a href="http://www.springframework.org/schema/beans" rel="nofollow">http://www.springframework.org/schema/beans</a><br>
<a href="http://www.springframework.org/schema/beans/spring-beans-2.5.xsd%22%3E" rel="nofollow">http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"&gt;</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;bean id=&quot;x&quot; class=&quot;java.lang.String&quot; scope=&quot;prototype&quot;&gt;
    &lt;constructor-arg&gt;&lt;value&gt;PARENT value&lt;/value&gt;&lt;/constructor-arg&gt;
&lt;/bean&gt;"><pre class="notranslate"><code class="notranslate">&lt;bean id="x" class="java.lang.String" scope="prototype"&gt;
    &lt;constructor-arg&gt;&lt;value&gt;PARENT value&lt;/value&gt;&lt;/constructor-arg&gt;
&lt;/bean&gt;
</code></pre></div>
<p dir="auto">&lt;/beans&gt;</p>
<p dir="auto">Error</p>
<hr>
<p dir="auto">log4j:WARN No appenders could be found for logger (org.springframework.core.CollectionFactory).<br>
log4j:WARN Please initialize the log4j system properly.<br>
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'x' defined in class path resource [app.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<br>
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:254)<br>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:925)<br>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:823)<br>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)<br>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)<br>
at java.security.AccessController.doPrivileged(Native Method)<br>
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)<br>
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:283)<br>
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)<br>
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)<br>
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:881)<br>
at IllegalArgumentProblem.main(IllegalArgumentProblem.java:21)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br>
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br>
at java.lang.reflect.Method.invoke(Method.java:597)<br>
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)<br>
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<br>
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:111)<br>
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87)<br>
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:248)<br>
... 16 more<br>
Caused by: java.lang.IllegalArgumentException: argument type mismatch<br>
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)<br>
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)<br>
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)<br>
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)<br>
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100)<br>
... 18 more</p>
<p dir="auto">Process finished with exit code 1</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.5.5, 2.5.6</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398093748" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/10240" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/10240/hovercard" href="https://github.com/spring-projects/spring-framework/issues/10240">#10240</a> not singleton StringBeans (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/12ce250c6ce911774a7983905fd6e006b5a1eac1/hovercard" href="https://github.com/spring-projects/spring-framework/commit/12ce250c6ce911774a7983905fd6e006b5a1eac1"><tt>12ce250</tt></a></p>