Constructor Injection with Non-String Map

In the following example, we will see constructor injection with Map. The map will have both key and value as non-strings. Key will be Employee which has the following fields:

  • Name
  • Employee ID
  • Department

Value will be Address which has the following parameters:

  • House No.
  • Pincode
  • State
  • Country

Spring – Constructor Injection with Non-String Map

In the Constructor Injection, the dependency injection will be injected with the help of constructors. Now to set the dependency injection as constructor dependency injection(CDI) in bean is done through the bean-configuration file. For this, the property to be set with the constructor dependency injection is declared under the <constructor-arg> tag in the bean-config file.

Constructor Injection with Collection

Spring frameworks provide us the facility to inject collection values via a constructor in our spring application. The following collections can be used inside the <constructor-arg> tag:

  • list
  • set
  • map

Similar Reads

Constructor Injection with Non-String Map

In the following example, we will see constructor injection with Map. The map will have both key and value as non-strings. Key will be Employee which has the following fields:...

Implementation of Constructor Injection with Non-String Map in Spring

Below is the implementation with class files of constructor injection with non-string map in a Spring application....

Contact Us