首页 > 解决方案 > 如何将 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) {

    }
}

标签: componentsosgircpe4

解决方案


推荐阅读