mehrere Instanzen von autowired bean

Wenn eine bean ist autowired, tut es erstellen Sie mehrere Instanzen der Klasse?

Ist hier ein Beispiel;

public class ClassA {

  @Autowired
  private ClassB classB;

  public ClassB getClassB() {
    return classB;
  }

  public void setClassB(ClassB classB) {
    this.classB = classB;
  }

  //using ClassB in method 1
  public void useClassBmethod1() {
    //currently using autowired ClassB instance
    classB.doSomething();
  }

  //using ClassB in method 2
  public void useClassBMethod2() {
    //need a new instance of ClassB but through the same autowired bean
    ClassB classb = getClassB();
  }
}

public class ClassB {


  public void doSomething() {}
}

Also meine Frage ist, hat autowiring eine Bohne wissen, wie man erstellen Sie eine neue Instanz einer bean, wenn erforderlich oder dies bleibt dem Programmierer zu entziffern?

Dank für die Unterstützung aus.

InformationsquelleAutor drecute | 2013-11-05

Schreibe einen Kommentar