Tuesday, January 24, 2012

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.
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:

Blog Widget by LinkWithin

JS-Kit Comments

  © Blogger template Newspaper III by Ourblogtemplates.com 2008

Back to TOP