Converting java map into spring map configuration

180 Views Asked by At

I have created a map as shown below in java program which now i want to make through spring way that is map used in this program i want to keep them configured through spring xml , rite now is the output of the program

TradeRef = AAA
TF = AAA
Traes = AAA
Deaswe = BBB
TraRef = AAA
Dealdt = BBB
Daelet = BBB
Deadery = BBB

so as you can see that values are hardcoded rite now in map as it is below java program which i am trying to convert in spring specially the way spring xml is being configured with respect to Map so please advise how can i set the values in spring map itself how would be my spring map xml would be to obtain the same functionality

as the below is the key value pair that i want to configure

KEY          VALUE 
TF             AAA
Traes          AAA
Deaswe         BBB
TraRef         AAA
Dealdt         BBB
Daelet         BBB
Deadery        BBB

below is the java class

public class testMap {

    public static void main(String[] args)
    {


        Map<String, List<String>> dataMap = new HashMap<String, List<String>>();
        dataMap.put ("AAA", Arrays.asList("TradeRef", "TraRef", "TF", "Traes"));
        dataMap.put ("BBB", Arrays.asList("Dealdt", "Daelet", "Deadery", "Deaswe"));


        Map<String, String> itemMap = new HashMap<String, String>(); //New map for item->key mapping
        for(String key: dataMap.keySet()) //Get all keys and iterate through
            for(String item: dataMap.get(key)) //For each item in your value list
                itemMap.put(item, key); //Create new mapping item->key



         Iterator it = itemMap.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry pair = (Map.Entry)it.next();
                System.out.println(pair.getKey() + " = " + pair.getValue());
                it.remove(); // avoids a ConcurrentModificationException





         }
    }
}
0

There are 0 best solutions below