Spring Dependency Inject using Constructor

In Constructor based DI(Dependency Injection), Objects define their dependencies via Constructor argument(<constructor-arg> tag) and Container invoke Constructors to set these arguments in object.

Address Bean Class

Above Bean Class has two Constructor one with multiple argument for different property while other takes single argument as List.

Spring Configuration File

Execute the Programme

Output of the above Application would be

Environment Used

Tool : Eclipse Indigo

Java : JDK 1.6

Spring : 3.1.1

Jars Required :

  • org.springframework.core-3.1.1.RELEASE.jar
  • org.springframework.context-3.1.1.RELEASE.jar
  • org.springframework.asm-3.1.1.RELEASE.jar
  • org.springframework.beans-3.1.1.RELEASE.jar
  • org.springframework.expression-3.1.1.RELEASE.jar
  • commong-logging-1.1.1.jar

Leave A Comment

Your email address will not be published. Required fields are marked *