Home » Spring Setter Injection with non-string Map

Spring Setter Injection with non-string Map

by Online Tutorials Library

Setter Injection with Non-String Map (having dependent Object) Example

In this example, we are using map as the answer that have Answer and User. Here, we are using key and value pair both as an object. Answer has its own information such as answerId, answer and postedDate, User has its own information such as userId, username, emailId.

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

Question.java

This class contains three properties, getters & setters and displayInfo() method to display the information.

Answer.java

User.java

applicationContext.xml

The key-ref and value-ref attributes of entry element is used to define the reference of bean in the map.

Test.java

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

You may also like