drndivoje
drndivoje

Reputation: 319

Injecting spring bean in Hazelcast entry listener

I am using Hazelcast 2.6 with Spring. Currently I have entry listener configured using spring-hazelcast configuration. For method entryEvicted I want to call method of my spring bean. Is it possible to inject that bean via xml configuration (or annotation) where is my entry listener configured. Here is sample code of my entry listener.

public class HazelcastSessionMapEntryListener implements EntryListener<String,SessionMapEntry>{
    private CustomBean customBean;
    @Override
    public void entryEvicted(EntryEvent<String, SessionMapEntry> event) {
      customBean.method(event);
    }....}

I am wondering is it possible to have instance of customBean injected without calling application context getBean method from my code.

Upvotes: 2

Views: 2051

Answers (1)

asimarslan
asimarslan

Reputation: 235

In Hazelcast you can configure a spring bean as a listener and configure that bean how ever you like. Here is a sample for your case;

 <hz:listeners>
     <hz:listener implementation="entryListener"/>
 </hz:listeners>

 <bean id="entryListener" class="com.acme.EntryListener">
     <property name="customBean" ref="customBean" />
 </bean>

 <bean name="customBean" class="com.acme.CustomBean"/>

Upvotes: 4

Related Questions