java - Multiple objects getting created when using Spring dependency injection using mixed configuration -


i seem encounter problem, when i'm configuring dependency injection classes using annotations , others through configuration in xml files.

i have constructor injection, need inject superbean object constructor of 2 classes , different instances of superbean because 1 configured annotation , other 1 in xml file, superbean defined this:

@component("superbean") public class superbean extends injectablebean { 

the constructor of class annotation configured constructor:

@autowired     public custombean(@value("any name") string name, @qualifier("superbean") superbean superbean) {         super();         this.superbean = superbean;         this.name = name;     } 

and other class' constructor:

public customxmlbean(string name, superbean superbean) {         super(name, superbean);     } 

and it's configuration in xml file:

    <bean id="customxmlbean" class="org.arturas.summerfav.beans.customxmlbean">     <constructor-arg name="name" type="string" value="the big custom xml bean" />     <constructor-arg>         <bean name="superbean" class="org.arturas.summerfav.beans.superbean" />     </constructor-arg> </bean> 

so seemed notice xml configured class seems have different instance of superbean, because changes made on superbean object not reflected when accessing through xml configured class.

so how can ensure there's 1 instance of superbean here? (let's assume want keep both ways of configuring - through xml file , through annotations)

edit: adding more source:

the custombean class:

@component("custombean") public class custombean extends injectablebean {      private string name;     private superbean superbean;      /**      * @param name - bean name      */     @autowired     public custombean(@value("any name") string name, @qualifier("superbean") superbean superbean) {         super();         this.superbean = superbean;         this.name = name;     } 

the customxmlbean class:

public class customxmlbean extends custombean {  public customxmlbean(string name, superbean superbean) {     super(name, superbean); } 

why constructor returning different class custombean - can please post entire source ?

edit: adding answer comments main answer

sorry, got mislead initial post. try

<constructor-arg index="1" ref="superbean"/> 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -