components - 如何将 IEventBroker 注入 e4 OSGI 服务组件
问题描述
我正在尝试将 IEventBroker 注入我的代码以发送通知。
其他一切正常,但 eventBroker 永远不会被注入。我没有收到任何编译时错误。
它只是在执行代码时出现 null 。
我已经修剪了代码,因为它不允许我提交它。
提前感谢您的帮助!
package com.test.services.internal;
imports ...
@Component
public class EnvironmentServiceImpl implements IEnvironmentService {
@Inject
private IEventBroker eventBroker;
private EntityManagerFactory entityManagerFactory;
private EntityManager entityManager;
@Activate
@SuppressWarnings("unchecked")
protected void activateComponent() {
getAll(environments -> {
if (environments.isEmpty()) {
List<Environment> initialModel = getMockEnvironments();
initialModel.forEach(this::save);
}
});
}
@Deactivate
protected void deactivateComponent() {
}
@Override
public void getAll(Consumer<List<Environment>> taskConsumer) {
eventBroker.post(EnvironmentEventConstants.TOPIC_ENVIRONMENT_LOADED,
createEventData(EnvironmentEventConstants.TOPIC_ENVIRONMENT_LOADED, updateEnvironment.getId()));
}
private Map<String, String> createEventData(String topic, String environmentId) {
}
}
解决方案
推荐阅读
- macos - MacBook Pro - 语言自动更改,需要永久修复
- dml - 从 GCP 控制台禁用 DML 执行
- wifi - ESP32 扫描时看不到 Wifi 网络?
- javascript - reactjs如何过滤/检查数组中的任何对象是否存在于另一个对象数组中?
- c++ - 解决方案在第 25 行执行时出现错误“越界”
- angular - 延迟加载模块的 Angular PreloadAllModules 不起作用
- r - Docker:如何获得 $HOME 的所有权?
- java - TextView hieght = wrap_content 不起作用
- c# - 从字节加载 UTf8 在 C# 中无法按预期工作
- extjs - 如何优化子组件内事件的布局性能?