gpt4 book ai didi

spring - Hazelcast map 存储类的 Bean 注入(inject)失败

转载 作者:行者123 更新时间:2023-12-02 08:14:44 25 4
gpt4 key购买 nike

我想注入(inject)一个 Bean,它将持久保存 hazelcast 上的 map 条目。

<map name="storethiselements-map">
<backup-count>1</backup-count>
<map-store enabled="true">
<class-name>name.of.MapPersistenceObject</class-name>
<write-delay-seconds>0</write-delay-seconds>
</map-store>
</map>

这些是 hazelcast 实例的构造函数参数。在 MapPersistenceObject 中,存在一个负责持久化条目的服务。我已将 MapPersistenceObject 标记为组件,并使服务对象 Autowiring ,以便 Spring 将使用正确的数据源注入(inject)正确的服务 Bean。

我已经尝试过这个,但我得到了一个应该注入(inject)服务的 NullPointer 。在我看来,Spring 无法将 MapPersistenceObject 与服务连接或 Autowiring 。它看起来像这样:

@Component
public class MapPersistenceObject implements
MapLoader<Long, DeviceWakeupAction>, MapStore<Long, DeviceWakeupAction> {
@Autowired
StoreMapEntries storeMapEntriesService;
[...]

也许有人知道问题的解决方案?

问候&&蒂亚 黑色CC

最佳答案

您应该使用 Spring 配置,而不是 Hazelcast xml 配置。

<hz:hazelcast id="hazelcast">
<hz:config>
...
<hz:map name="storethiselements-map" backup-count="1">
<hz:map-store enabled="true" implementation="mapPersistenceObject" write-delay-seconds="0"/>
</hz:map>
...
</hz:config>
</hz:hazelcast>

<bean id="mapPersistenceObject" class="name.of.MapPersistenceObject"/>

参见Hazelcast Spring integration .

关于spring - Hazelcast map 存储类的 Bean 注入(inject)失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9995269/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com