<hz:map id="loggedInUserMap" name="loggedInUserMap" instance-ref="ipds" scope="singleton" />
This will create a bean named 'loggedInUserMap' (specified by the id attribute). The name of the map in the Hazelcast context will also be "loggedInUserMap" (indicated by the name attribute).
Tag
A <hz:map> inside <hz:config> refers to a specific configuration that can be used when creating an IMap (here referred to as MapConfig ). There may be many such MapConfigs . A single MapConfig can be shared across multiple IMaps using a wildcard * .
If you have a MapConfig with a name that matches the map name used in the hazelcast context, this configuration will be used when creating this IMap. In your case, this is "loggedInUserMap".
If not found, a MapConfig named "default" will be used to create this IMap.
If not found, the default values ββfor IMap will be used when creating this IMap object.
I think the following example will clearly figure it out.
Configuration example
<hz:config> <hz:instance-name>${hz.instance.name}</hz:instance-name> <hz:group name="${hz.group.name}" password="${hz.group.password}"/> <hz:map name="default" backup-count="2" max-size="0" time-to-live-seconds="25" eviction-percentage="30" eviction-policy="NONE"/> <hz:map name="userMap" backup-count="2" max-size="0" time-to-live-seconds="6000" eviction-percentage="30" eviction-policy="NONE"/> <hz:map name="FruitMap*" backup-count="2" max-size="0" time-to-live-seconds="10" eviction-percentage="30" eviction-policy="NONE"/> </hz:config> <hz:map instance-ref="ipds" id="userMapSpringId" name="userMap" /> <hz:map instance-ref="ipds" id="mangoMapSpringId" name="FruitMap1" /> <hz:map instance-ref="ipds" id="appleMapSpringId" name="FruitMap2" /> <hz:map instance-ref="ipds" id="alientFruitMapSpringId" name="AlienFruit" />
Code example
IMap map1 = (IMap) ctx.getBean("userMapSpringId"); // map1 will make use of the configuration with name "userMap" IMap map2 = (IMap) ctx.getBean("mangoMapSpringId"); IMap map3 = (IMap) ctx.getBean("appleMapSpringId"); // Here two different IMaps objects are created. // However both map2 and map3 will make use of the same configuration "FruitMap*". IMap map4 = (IMap) ctx.getBean("alientFruitMapSpringId"); // In the case of map4, there is no configuration which matches its hazelcast name // (AlienFruit). Hence it will make use of the configuration with name "default".
I hope the code snippet with comments is self-explanatory.
source share