I'm trying to do field-level injection so I don't have to pass "models" when my controllers are instantiated, like,
UserController controller = new UserController(/*No need to pass models here*/);
However my application throws NullPointerException, here my code:
UserController.java
public class UserController implements Controller {
@Inject private UserModel model;
public UserController() {
model.doSomething(); // NullPointerException
}
}
ClientGinModule.java
public class ClientGinModule extends AbstractGinModule {
@Override
protected void configure() {
bind(UserModel.class).in(Singleton.class);
}
}
What could be the problem?