I have a module that acquires and holds an API token (simplified):
@Singleton
public class KeyHolderModule extends AbstractModule {
// This doesn't seem to be injected
private @Inject TokenConnector connector;
private DateTime keyLastRefreshed;
private String key;
private Credentials creds = config.getCreds();
@Override protected void configure() {
this.key = connector.getToken(creds);
this.keyLastRefreshed = DateTime.now();
}
@Provides @Named("apiKey") public String getKey() {
// logic to check key last refreshed and handle generating a new one
return this.key;
}
}
I get a null pointer error on the line where I try to access the connector (this.key = connector.getToken(creds);
), so the connector is obviously not getting wired up correctly.
I've tried creating a constructor and using @Inject there, but I'm manually adding these modules via new
to a list in my app bootstrap class, so that's sort of out.
Obviously I'm missing something here -- I could probably just new
up a TokenConnector
in this case since it doesn't have any dependencies itself, but that wouldn't fix my fundamental failure to grasp what's happening here. So if you want to see (simplified) other pieces of code, or less simplified pieces of this code, let me know.