<hz:map id="loggedInUserMap" name="loggedInUserMap"
instance-ref="ipds" scope="singleton" />
This will result in creation of a bean named 'loggedInUserMap' (pointed by id
attribute). The name of the map in Hazelcast context will be also "loggedInUserMap" (pointed by name
attribute).
A <hz:map>
tag inside <hz:config>
refers to a specific configuration that can be used while creating an IMap
(Here by referred to as MapConfig
). There could be many such MapConfigs
in a hazelcast.xml. One MapConfig
can be shared by multiple IMaps as well using wildcard *
.
If you have a MapConfig with name
that matches with the map "name" used in hazelcast context, then that configuration will be used while creating that IMap object. In your case it is "loggedInUserMap".
If not found, MapConfig with name "default" will be used to create that IMap object.
If not found, defaults for the IMap will be used while creating that IMap object.
I think the following example will sort things out clearly.
Sample Config
<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" />
Sample code
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 are self-explanatory.