Guice Konfiguration Fehler: Konnte nicht finden, eine geeignete Konstruktor

Ich bin mit GUICE für dependency injection für eine RESTful API bauen mit Dropwizard. Dies ist die Fehlermeldung die ich erhalte:

com.google.injizieren.ConfigurationException: Guice Konfiguration-Fehler:

1) Konnte nicht finden, eine geeignete Konstruktor in
com.api.analytics.Besucher.web.VisitorParams. Klassen haben muss
entweder eine (und nur eine) annotierten Konstruktor mit @Inject oder eine
null-argument-Konstruktor, der nicht privat ist. bei
com.api.analytics.visitor.web.VisitorParams.class(VisitorParams.java:27)
bei der Lokalisierung com.api.analytics.Besucher.web.VisitorParams
für parameter 0 bei com.api.analytics.Besucher.web.v1.VisitorResource.(VisitorResource.java:68)
bei der Lokalisierung
com.api.analytics.Besucher.web.v1.VisitorResource

Hier ist, wie meine Ressource-setup:

package com.api.analytics.visitor.web.v1;

//imports

@Path("/visitor")
@Produces({MediaType.APPLICATION_JSON, ExtraMediaTypes.PROTOBUF})
@Consumes(MediaType.APPLICATION_JSON)
public class VisitorResource {
  private final ContactsManager contactsManager;
  private final ActivityFetcher.Provider activityFetcherProvider;
  private final VisitSourceMapper visitSourceMapper;
  private final TimeZoneClient timeZoneClient;
  private final GatesClient gatesClient;
  private final Value<Integer> smallScanLimit;
  private final Provider<Integer> portalIdProvider;
  private final VisitorParams visitorParams;

  @Inject
  public VisitorResource(@Bind({Bind.Params.QUERY}) VisitorParams visitorParams,
                         ContactsManager contactsManager,
                         ActivityFetcher.Provider activityFetcherProvider,
                         VisitSourceMapper visitSourceMapper,
                         TimeZoneClient timeZoneClient,
                         GatesClient gatesClient,
                         @Named("analytics.activities.fetch.small.scan.limit") Value<Integer> smallScanLimit,
                         @StashedHubId Provider<Integer> portalIdProvider) {
    this.contactsManager = contactsManager;
    this.activityFetcherProvider = activityFetcherProvider;
    this.visitSourceMapper = visitSourceMapper;
    this.timeZoneClient = timeZoneClient;
    this.gatesClient = gatesClient;
    this.smallScanLimit = smallScanLimit;
    this.portalIdProvider = portalIdProvider;
    this.visitorParams = visitorParams;
  }

  @Timed
  @GET
  @Path("/{identity}/activities")
  public List<Activity> getActivitiesGet(@PathParam("identity") String identity) throws Exception {
    return getActivities(identity);
  }

  //other methods
}

Hier ist mein VisitorParams Klasse:

package com.api.analytics.visitor.web;

//imports

public class VisitorParams {
  private final Optional<Long> start;
  private final Optional<Long> end;
  private final Set<ActivityType> activityTypes;
  private final Optional<Integer> limit;
  private final boolean reversed;
  private final Set<Long> vids;

  @JsonCreator
  public VisitorParams (@JsonProperty("start") Optional<Long> start,
                        @JsonProperty("end") Optional<Long> end,
                        @JsonProperty("type") Optional<Set<ActivityType>> activityTypes,
                        @JsonProperty("limit") Optional<Integer> limit,
                        @JsonProperty("reversed") @DefaultValue("false") boolean reversed,
                        @JsonProperty("vid") Optional<Set<Long>> vids) {
    this.start = start;
    this.end = end;
    this.activityTypes = activityTypes.or(Collections.emptySet());
    this.limit = limit;
    this.reversed = reversed;
    this.vids = vids.or(Collections.emptySet());
  }

  public Optional<Long> getStart() {
    return this.start;
  }

  //other getters
}

Eine Sache, die ich habe versucht, das hinzufügen einen Konstruktor in meinem VisitorParams Klasse wie folgt aus:

public VisitorParams () {}

Wenn ich das getan habe, bekomme ich Fehler über, wie einige Variablen might not have been initialized.

Also, was mache ich hier falsch, dieses zu verursachen Konfigurationsfehler? Ich bin ziemlich neu mit Guice und Dropwizard, so lassen Sie mich wissen, wenn Sie weitere Informationen benötigen. Danke!

InformationsquelleAutor Di Zou | 2016-04-12

Schreibe einen Kommentar