【问题标题】:How to use OSGi service reference into whole other classes?如何将 OSGi 服务引用用于整个其他类?
【发布时间】:2017-06-06 09:40:51
【问题描述】:

我有一个捆绑激活器类和一些代码。 我需要在我的捆绑激活器类中使用@Autowired。它不工作。 这是我的捆绑激活器类,

public class ProviderActivator implements BundleActivator {

    @Autowired
    public TestingClass testingClass;

    public void start(final BundleContext bundleContext) throws Exception {
        System.out.println("bundle starter!!!!!!!!!!!!!!" +testingClass );
        }
}

testingClass SOP 为空。在 spring-context.xml 中添加了 Spring 上下文扫描。

我的建议是,

bundleActivator 类加载后注入的 bean。

如何预防?为什么启动bundle类时bean为空?

【问题讨论】:

  • 嗨@Sridhar 它取决于你的捆绑包是如何启动的。如果您使用纯 Java、Spring 或 Blueprint。 Blueprint 与 Spring 非常相似,您使用 XML 文件来配置 bean 并注入到其他类中。您可能想阅读以下内容:blog.knowhowlab.org/2010/10/…
  • 那么请编辑您的问题并指定如何激活您的捆绑包

标签: apache-camel osgi esb jbossfuse karaf


【解决方案1】:

为什么您甚至会期望这会起作用?激活器类由 OSGi 框架实例化,@Autowired 不是 OSGi 功能。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-29
    • 2013-06-14
    • 2016-04-06
    • 2016-02-27
    • 2017-02-15
    • 1970-01-01
    • 2017-11-10
    • 2017-11-25
    相关资源
    最近更新 更多