91-9990449935 0120-4256464 |
Constructor Injection with Non-String Map (having dependent Object) ExampleIn 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.javaThis class contains three properties, two constructors and displayInfo() method to display the information. Answer.java User.java applicationContext.xmlThe key-ref and value-ref attributes of entry element is used to define the reference of bean in the map. Test.javaThis class gets the bean from the applicationContext.xml file and calls the displayInfo() method to display the information.
download this example (developed using MyEclipse IDE)
download this example (developed using Eclipse IDE) |