Master Mind
Master Mind

Reputation: 3084

Dropwizard 0.8 and GuiceBundle Governator: Forcing Resources class to be Singleton

I'm using Dropwizard 0.8.1 and I have observed that resource object is created each time a belonging path is called.

I think this done because the resource are registered by class when the application is bootstraped.

Is there anyway to force the resources to be Singleton?

I have tried to use @Singleton and @LazySingleton (via Governator) but it seems not to work. How can I fix this?

Upvotes: 2

Views: 591

Answers (1)

durron597
durron597

Reputation: 32323

Guice will override bindings when you specify them as a class annotation. Documentation:

If there's conflicting scopes on a type and in a bind() statement, the bind() statement's scope will be used. If a type is annotated with a scope that you don't want, bind it to Scopes.NO_SCOPE.

You can fix this by specifying Singleton in your binding in your Module, e.g.

protected void configure() {
    bind(Foo.class).toProvider(FooProvider.class).in(Singleton.class);
}

Upvotes: 2

Related Questions