1.

 Explain different dependency injection patterns.

Answer»

Three Annotation-Based Injection Patterns

  • Field injection
import org.springframework.beans.factory.annotation.Autowired; PUBLIC CLASS MyClass { @Autowired private OtherClass otherClass ; //Business LOGIC... }
  • Setter injection
import org.springframework.beans.factory.annotation.Autowired; public class MyClass { private OtherClass otherClass ; @Autowired public VOID setOtherClass(final OtherClass otherClass) { this.otherClass = otherClass ; } //Business logic... }public class MyClass { private final OtherClass anotherBean; public MyClass(final OtherClass otherClass) { this.otherClass = otherClass; } //Business logic... }


Discussion

No Comment Found