Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bean-Injection failed at Hazelcast map-store class

I wanna inject a bean which will persist the map-entries at hazelcast.

<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>

These are constructor-args for the hazelcast-instance. In the MapPersistenceObject there exists a Service which is responsible for persisting the entries. I have marked MapPersistenceObject as component and made the Service-Object Autowired so that Spring will inject the right Service-Bean with the right Datasource.

I have tried this but i get a NullPointer where the Service should be injected. It seems to me that Spring can't connect or autowire the MapPersistenceObject with the Service. It looks like this:

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

Maybe somebody knows a solution of the problem?

regards && tia noircc

like image 684
noircc Avatar asked Dec 21 '25 11:12

noircc


1 Answers

You should use Spring configuration, not Hazelcast xml configuration.

<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"/>

See Hazelcast Spring integration.

like image 178
mdogan Avatar answered Dec 24 '25 01:12

mdogan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!