Create HashMap Spring XML Example

Create HashMap Spring XML Example

While working with Spring framework where you define object model as bean in your Spring context file, you could also define HashMap as bean in your XML definition as below:

To access above definition from java class please use below:


  • Test class to load context file and print its value:

Please note: You can not use @Autowired if try to access Map in place of HashMap. You will have to use @Resource instead as shown above.


Leave a Reply

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