Defining annotation

Let's define @Autowired for the previous example. Our goal is to remove the XML configuration <property name="professor" ref="professor" /> for the subject bean with the @Autowired annotation. Let's modify a setter method of the Subject class and Spring application (XML) context file, as follows:

//Updated setter injection method  @Autowired  public void setProfessor(Professor professor) {    System.out.println("setting the professor through setter method injection ");    this.professor = professor;  }//Updated XML configuration<bean id="professor" class="com.packet.spring.annotation.di.Professor">      <property name="name" value="Nilang" /></bean>    <bean id="subject" class="com.packet.spring.annotation.di.Subject"></bean>

We are expected ...

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.