Javatpoint Logo
Javatpoint Logo

Constructor Injection with Map Example

In this example, we are using map as the answer that have answer with posted username. Here, we are using key and value pair both as a string.

Like previous examples, it is the example of forum where one question can have multiple answers.

Question.java

This class contains three properties, two constructors and displayInfo() method to display the information.

applicationContext.xml

The entry attribute of map is used to define the key and value information.

Test.java

This class gets the bean from the applicationContext.xml file and calls the displayInfo() method.






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA