【问题标题】:Eclipse e4 OSGI Service @Component AnnotationEclipse e4 OSGI 服务 @Component 注解
【发布时间】:2016-08-05 14:13:26
【问题描述】:

如果在我的 MANIFEXT.MF 中创建以下 OSGI-INF/service.xml 并通过 Service-Component: OSGi-INF/service.xml 设置它

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="EvalManagerContextFunction">

   <implementation class="x.y.context.EvalManagerContextFunction"/>

   <property name="service.context.key" type="String" value="x.y.eval.EvalManager"/>

   <service>
      <provide interface="org.eclipse.e4.core.contexts.IContextFunction"/>
   </service>

</scr:component>

如果第一次请求,则创建 EvalManager(调用 ContextFunction Class compute

现在,如果我尝试对注释执行相同操作,则不会调用 compute 函数。

@Component(name = "EvalManagerContextFunction", service = IContextFunction.class, property = "service.context.key=x.y.eval.EvalManager")
public class EvalManagerContextFunction extends ContextFunction {

    @Override
    public Object compute(IEclipseContext context, String contextKey) {

        EvalManager manager = ContextInjectionFactory.make(EvalManager.class, context);

        context.get(MApplication.class).getContext().set(EvalManager.class, ContextInjectionFactory.make(EvalManager.class, context));

        return manager;

    }

}

【问题讨论】:

    标签: osgi rcp e4


    【解决方案1】:

    我在 Eclipse 核心源代码的任何地方都看不到对 @Component 注释类的任何引用,因此它似乎不受支持。

    Eclipse Marketplace 中有一个插件here 似乎增加了对此的支持(我没有尝试过)。

    更新:Eclipse Neon Milestone 6 (4.6M6) 版本中添加了对此的支持。

    【讨论】:

    • 好的,谢谢格雷格。我现在将使用 xml 文件。
    • 我已经使用了你提到的 DS 支持插件,它运行良好。每当您更改组件时,该插件都会自动创建 XML 定义文件。
    • 我正在使用 Neon M6,但由于插件不兼容而失败。这个插件的作者回答了一个问题,他说它应该在 Neon M6 中工作而无需添加一些额外的插件Dirk, the functionality implemented by this plugin has been added directly to Eclipse PDE as of Neon M6 (to be released shortly). See https://bugs.eclipse.org/bugs/show_bug.cgi?id=376950
    • 在答案中添加了关于 Eclipse Neon 的注释。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-10
    • 2018-07-15
    • 2014-08-07
    • 2020-12-31
    • 1970-01-01
    • 2014-12-15
    • 2021-01-05
    相关资源
    最近更新 更多