在<hz:map>中创建的applicationContext标记与在<hz:config>段中定义的标记之间有什么区别?
它们之间有什么关系?
我知道,<hz:map> in applicationContext会导致创建一个类型为IMap的bean,而当没有<hz:map>时,它就不会创建了。
但是,当定义了bean并随后在hazelcast配置下具有同名的<hz:map>时,下面的配置会做什么?
<hz:map id="loggedInUserMap" name="loggedInUserMap" instance-ref="ipds" scope="singleton" />
<hz:hazelcast id="ipds">
<hz:config>
<hz:instance-name>${hz.instance.name}</hz:instance-name>
<hz:group name="${hz.group.name}" password="${hz.group.password}"/>
<hz:map name="loggedInUserMap" backup-count="1" eviction-policy="NONE" in-memory-format="BINARY">
<hz:near-cache time-to-live-seconds="0" max-idle-seconds="60"
eviction-policy="LRU" max-size="5000" invalidate-on-change="true"/>
</hz:map>
</hz:config>
</hz:hazelcast>发布于 2015-10-20 15:22:56
<hz:map id="loggedInUserMap" name="loggedInUserMap"
instance-ref="ipds" scope="singleton" />这将导致创建一个名为“loggedInUserMap”的bean (由id属性指向)。Hazelcast上下文中映射的名称也将是"loggedInUserMap“(由name属性指向)。
A <hz:map>标记在<hz:config>中是指在创建IMap (此处称为MapConfig)时可以使用的特定配置。在一个MapConfigs中可能有许多这样的hazelcast.xml。一个MapConfig也可以由多个IMaps使用通配符*共享。
如果您有一个带有MapConfig的name,它与hazelcast上下文中使用的映射“名称”相匹配,那么在创建IMap对象时将使用该配置。在您的例子中,它是"loggedInUserMap“。
如果没有找到,名为"default“的MapConfig将用于创建该IMap对象。
如果未找到,则在创建该IMap对象时将使用IMap的默认值。
我想下面的例子会把事情弄清楚。
样本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" />样本代码
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".我希望带有注释的代码片段是不言自明的。
https://stackoverflow.com/questions/33232845
复制相似问题