2
我是新來的春季開機和榛子。我有一個應用了hazelcast imap的服務層的spring-boot應用程序。我遇到的問題是,我不知道如何獲取將數據存儲到僅具有java配置的彈簧組件的mapstore。添加組件註釋是不夠的,我的自動裝配倉庫爲空。Hazelcast MapStore as Spring Component
@Component
public class MyMapStore extends implements MapStore<Long, MyClass>, MapLoaderLifecycleSupport{
@Autowired
private MyRepository repository;
...
}
我寫了一個靜態ContextAccessor手動加載我的豆,但在IDE的環境中,這只是工作,而不是如果我開始我的應用程序的jar
@Component
public class MyMapStore extends implements MapStore<Long, MyClass>, MapLoaderLifecycleSupport{
private MyRepository repository = StaticContextAccessor.getBean(MyRepository.class);
...
}
這裏的問題是,並非所有的bean已經加載了bean並且存儲庫未被初始化。
是否有任何可能性讓mapstore作爲spring組件運行,甚至強制hazelcast在我的存儲庫加載後進行初始化? 感謝您的幫助。
我有一個解決方案,但我不是很滿意它。我在我的Hazelcast配置中初始化地圖存儲,並將庫添加爲構造函數arg。這可行,但商店甚至不是真正的春季組件。 'mapStoreConfig.setImplementation(new MyMapStore(this.repository));' 如果有人能幫助我找到更好的解決方案,那將會很好。 – pDer666