Reputation: 3084
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
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, thebind()
statement's scope will be used. If a type is annotated with a scope that you don't want, bind it toScopes.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