Java Spring Framework Dependency Injection Variants
Variants in Java Spring Framework Dependency Injection:
Constructor dependency Injection: Dependencies are provided through the constructors of the component.
Constructor dependency Injection: Dependencies are provided through the constructors of the component.
Setter dependency injection: Dependencies are provided through the JavaBeanstyle setter methods of the component and are more popular than Constructor dependency injection.
Constructor Dependency Injection Syntax:
public class ConstructorInjection
{
private Dependency dep;
public ConstructorInjection(Dependency dep)
{
this.dep = dep;
}
}
Setter Dependency Injection Syntax
public class SetterInjection
{
private Dependency dep;
public void setMyDependency(Dependency dep)
{
this.dep = dep;
}
}
0 comments:
Post a Comment