简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM