Dropwizard - 绑定不匹配:不是有界参数的有效替代

时间:2016-12-07 06:31:10

标签: java dropwizard

我正在启动dropwizard示例应用程序,我正在实现HelloWorldService。以下是我的课程。

但我收到错误

  

绑定不匹配:类型TaskManagerConfiguration无效   替代的有界参数   类型应用

在TaskManagerApplication.java和HelloWorldService.java类中。

有人可以帮我吗?

TaskManagerConfiguration.java

package com.nagra.taskManager.config;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.yammer.dropwizard.config.Configuration;

import org.hibernate.validator.constraints.*;

public class TaskManagerConfiguration extends Configuration {

   @NotEmpty
   @JsonProperty
   private String template;

   @NotEmpty
   @JsonProperty
   private String defaultName = "Stranger";

   public String getTemplate() {
       return template;
   }

   public String getDefaultName() {
       return defaultName;
   }
}

HelloWorldService.java

package com.nagra.taskManager.resources.service;

import com.nagra.taskManager.TaskManagerApplication;
import com.yammer.dropwizard.Service;
import com.yammer.dropwizard.config.Bootstrap;
import com.yammer.dropwizard.config.Environment;

public class HelloWorldService extends Service<TaskManagerApplication> {

   @Override
   public void initialize(Bootstrap<TaskManagerApplication> arg0) {
       // TODO Auto-generated method stub

   }

   @Override
   public void run(TaskManagerApplication arg0, Environment arg1)
        throws Exception {
       // TODO Auto-generated method stub

   }

}

和TaskManagerApplication.java

package com.nagra.taskManager;

import com.nagra.taskManager.config.TaskManagerConfiguration;

import io.dropwizard.Application;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;

public class TaskManagerApplication extends Application<TaskManagerConfiguration> {

   public static void main(final String[] args) throws Exception {
       new TaskManagerApplication().run(args);
   }

   @Override
   public String getName() {
       return "TaskManager";
   }

   @Override
   public void initialize(final Bootstrap<TaskManagerConfiguration> bootstrap) {
       // TODO: application initialization
   }

   @Override
   public void run(final TaskManagerConfiguration configuration,
                final Environment environment) {
       // TODO: implement application
   }

}

1 个答案:

答案 0 :(得分:0)

很少 -

  1. 确保从Configuration导入io.dropwizard.Configuration类,而不是当前使用的`com.yammer.dropwizard.config.Configuration;在你的TaskManagerConfiguration.java中。

  2. 如果您完成发布notes from dropwizard - 版本com.yammer.dropwizard.Service0.6.2之前使用的dropwizard已移至import io.dropwizard.Application;。因此,目前您的TaskManagerApplication可以用作运行此应用程序的主类。