簡體   English   中英

Google Guice 3和OSGi(Eclipse equinox)問題,

[英]Google Guice 3 and OSGi (Eclipse equinox) problem,

我在OSGi容器中運行Guice 3時遇到問題。 以下是我編寫的一個簡單測試,用於測試Guice是否與OSGi配合良好。

一個簡單的guice模塊,如:

public class Module extends AbstractModule {
    @Override
    protected void configure() {
    bind(IInterface.class).to(IImplement.class);
    }
}

IInterface和IImplement都非常簡單。

OSGi激活器是這樣的:

 public void start(BundleContext bundleContext) throws Exception {
        Activator.context = bundleContext;
        Injector inj = Guice.createInjector(new Module());
        IInterface e = inj.getInstance(IInterface.class);
        e.sayHello();
  }

在Eclipse中,我制作了一個包含所有Guice Jars的目標,為了讓guice自行解決,我為aopalliance.jar和javax.injector.jar做了兩個額外的包。

但是,這個簡單的測試無法加載測試包,給我錯誤信息抱怨無法找到一個無法找到的guice類:

  Exception in guicetest.Activator.start() of bundle guicetest
  Caused by: java.lang.NoClassDefFoundError:   com/google/inject/binder/AnnotatedBindingBuilder
at guicetest.guice.Module.configure(Module.java:11)

我希望我已經把問題弄清楚了。 誰能告訴我如何解決這個問題?

啊,在發布問題之后我找到了問題的根源。 我沒有在測試包的Import-Packages中指定有問題的類所在的com.google.inject.binder包。 雖然模塊不直接導入該包,但它看起來仍然需要指定所有間接依賴包。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM