2016-02-05 64 views
0

我是Dropwizard和Guice的新手,所以我遵循本教程:Dropwizard and Guice Integration。當執行主要方法時,我得到這個錯誤:Guice注射不與Dropwizard

default configuration has an error: 
    * message can not be found (was null) 

所以我猜Guice注射沒有工作。 我有相同的代碼作爲教程,只是我沒有plugins部分我pom.xml,我有這條線的主要方法:代替

new ServiceApplication().run(new String[] {"server"}); 

new ServiceApplication().run(args); 

我錯過了什麼嗎?有什麼我必須補充嗎?

謝謝。

回答

0

是的,你錯過了一個重要的位。 文章給出了運行dropwizard應用下面的命令(請注意server選項後面的字符串,它與配置選項指向的文件):

$ java -jar target/DropWizardGuice-1.0-SNAPSHOT.jar server config.yml

而且前面的文章中存在的說明配置.yml文件和Guice之間關係:

Now we need a bit of glue code that takes the message from the configuration file to make it available to Guice.

通過改變代碼在main方法:

new ServiceApplication().run(new String[] {"server"});

您明確拒絕提供它需要的關於配置選項的位置(包括您的情況下message屬性的值)的信息dropwizard。這就是錯誤信息所說的。