0

我编写了一个包含com.liferay.portal.security.audit.AuditMessageProcessor服务实现的模块:

@Component(
    configurationPid = "my.MyAuditMessageProcessorConfiguration",
    immediate = true,
    property = {
            "eventTypes=*",
            "service.ranking:Integer=100000"
    },
    service = AuditMessageProcessor.class
)
public class MyElasticsearchAuditMessageProcessor
        implements AuditMessageProcessor {

    @Override
    public void process(AuditMessage auditMessage) {
        _log.info("This never appears even after login/logout");
        elasticsearch.send(auditMessage);
    }

    @Activate
    @Modified
    protected void activate(Map<String, Object> properties) {
        _myAuditMessageProcessorConfiguration = ConfigurableUtil
            .createConfigurable(
                MyAuditMessageProcessorConfiguration.class, properties);
    }

    @Reference(unbind = "-")
    protected my.Elasticsearch elasticsearch;

    private static final Log _log =
        LogFactoryUtil.getLog(MyAuditMessageProcessor.class);

    private volatile MyAuditMessageProcessorConfiguration
        _myAuditMessageProcessorConfiguration;
}

弹性搜索.java:

@Component(
        immediate = true
    )
public class Elasticsearch {
    [...]
}

部署后,Gogo Shell 将我的模块视为未实现该服务,如下所示。我的模块实现的另外两个服务是可见的。

g! inspect capability service 548
myaudit_1.0.0 [548] provides:
---------------------------------
service; javax.servlet.Filter with properties:
   servlet-filter-name = Audit Download Filter
   url-pattern = /documents/*
   servlet-context-name = 
   component.name = my.DownloadFilter
   component.id = 2573
   service.id = 7181
   service.bundleid = 548
   service.scope = bundle
   Used by:
      org.eclipse.osgi_3.10.200.v20150831-0856 [0]
service; com.liferay.portal.kernel.portlet.bridges.mvc.MVCRenderCommand with properties:
   service.ranking = 100
   mvc.command.name = /document_library/view_file_entry
   javax.portlet.name = com_liferay_document_library_web_portlet_DLPortlet, com_liferay_document_library_web_portlet_DLAdminPortlet, com_liferay_document_library_web_portlet_IGDisplayPortlet
   component.name = my.MyViewFileEntryMVCRenderCommand
   component.id = 2576
   service.id = 7182
   service.bundleid = 548
   service.scope = bundle
   Used by:
      org.eclipse.osgi_3.10.200.v20150831-0856 [0]

我究竟做错了什么?

有关信息,在我的模块的 jar 中OSGI-INF/my.MyAuditMessageProcessor.xml存在:

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.3.0" name="my.MyAuditMessageProcessor" immediate="true" activate="activate" modified="activate" configuration-pid="my.MyAuditMessageProcessorConfiguration">
  <implementation class="my.MyAuditMessageProcessor"/>
  <service>
    <provide interface="com.liferay.portal.security.audit.AuditMessageProcessor"/>
  </service>
  <property name="eventTypes" type="String" value="*"/>
  <property name="service.ranking" type="Integer" value="100000"/>
</scr:component>
4

1 回答 1

3

正如 Christian 所提示的,问题是我的组件有不满足的要求。请注意,它与捆绑缺少的要求不同,它低于一个级别。

我的包已满足所有要求,但我的模块缺少要求。这是我发现它的方法:

  1. 启动 Gogo 外壳
  2. 类型scr:list
  3. 幸运的是,您的组件应该在长列表的末尾
  4. 这为您提供了组件的 id,例如 2587
  5. 类型scr:info 2587
  6. 这将显示UnsatisfiedReferenceTarget: null缺少的依赖项

就我而言,我试图直接@Reference @Component 而不是服务。我通过创建 ElasticsearchService 接口并让 Elasticsearch 组件实现它解决了这个问题。

于 2017-11-06T09:45:23.583 回答