gpt4 book ai didi

java - OSGi Felix 依赖管理器注解和抽象类

转载 作者:行者123 更新时间:2023-11-30 11:07:57 24 4
gpt4 key购买 nike

在基于依赖管理器的组件模型中,我试图将组件的所有样板文件隐藏到基类中。我在 eclipse+bndtools 中连接了所有东西,并且可以成功地将 @Init@Start@Stop 推送到我的基类中,但是当我移动时我的“命名”@ServiceReference 已启动,编译插件开始抛出错误。

对于一些进一步的上下文,这就是我的方法的样子,正如你所看到的,我正在动态地使用 initstart 方法,这样我就可以摆脱尽可能多的样板文件。

@ServiceDependency(name = "commands" )
protected void setCommands(CommandList commands) {
this.commands = commands;
}

@Init
Map init() {
return new HashMap() {{
put("commands.filter", Filter.property(Properties.COMMAND_LIST_ID, getCommandListId()));
put("commands.required", "true");
}};
}

@Start
Map start() {
...
return new HashMap() {{
put(Properties.COMMAND_LIST_LISTVIEW_ID, getCommandListViewId());
}};
}

这是 Eclipse 打印出的堆栈跟踪:

java.lang.Error: DM Annotation plugin failure
at org.apache.felix.dm.annotation.plugin.bnd.AnnotationPlugin.analyzeJar(AnnotationPlugin.java:130)
at aQute.bnd.osgi.Analyzer.doPlugins(Analyzer.java:588)
at aQute.bnd.osgi.Analyzer.analyze(Analyzer.java:171)
at aQute.bnd.osgi.Builder.analyze(Builder.java:344)
at aQute.bnd.osgi.Analyzer.calcManifest(Analyzer.java:618)
at aQute.bnd.osgi.Builder.build(Builder.java:81)
at aQute.bnd.osgi.Builder.builds(Builder.java:1243)
at aQute.bnd.build.ProjectBuilder.builds(ProjectBuilder.java:520)
at aQute.bnd.build.Project.buildLocal(Project.java:1417)
at org.bndtools.builder.NewBuilder.rebuild(NewBuilder.java:655)
at org.bndtools.builder.NewBuilder.rebuildIfLocalChanges(NewBuilder.java:545)
at org.bndtools.builder.NewBuilder.build(NewBuilder.java:199)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:734)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:299)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:302)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:358)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:381)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

在工作中,我们使用 Eclipse PDE + SCR(XML),它与抽象类继承配合得很好。现在我重新审视了纲要规范,它对 SCR 注释有这样的说法:

The Declarative Services Annotations are not inherited, they can only be used on a given class, anno- tations on its super class hierarchy or interfaces are not taken into account.


将我自己的依赖管理包装在程序依赖管理器之上似乎是合适的。我将调查/制作原型(prototype),看看效果如何。

最佳答案

我遇到了同样的问题,

问题是我的类没有使用@Component 注释进行注释。尝试将 @Component 添加到包含您在此处注意到的代码的当前类。

希望对你有帮助

关于java - OSGi Felix 依赖管理器注解和抽象类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28685201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com