DI through XML configuration

It's always good to start with the most common option. So first, we will take an example of pure XML-based configuration, as per the following snippet:

public class Professor {  private String name;  //Constructor  public Professor() {    System.out.println("Object of Professor is created");  }  public String getName() {    return name;  }  public void setName(String name) {    this.name = name;  }}public class Subject {  private Professor professor;  public Subject() {    System.out.println("Object of Subject is created");  }  //Setter injection method  public void setProfessor(Professor professor) {    System.out.println("setting the professor through setter method injection ");    this.professor = professor;  }  public void taughtBy() { if(professor ...

Get Java 9 Dependency Injection now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.