You are trying to access it in the constructor. The introduced dependencies are not available in the constructor. It is not possible to set an instance variable if the instance is not yet constructed. You basically expect it to work as follows:
test_servlet servlet; servlet.injBean = new doSomethingService(); servlet = new test_servlet();
This is clearly not the case. You can access it as early as possible in the servlet's init() method. It is also available only in any of the servlet's doXxx() methods.
To start, replace
public test_servlet() { super(); injBean.doSomething(); }
by
@Override public void init() { injBean.doSomething(); }
Not tied to a specific problem, I highly recommend working on Java naming conventions . Class names with lower and lower digits do not comply with standard Java naming conventions, which slows down the interpretation of code by experienced Java developers.
Balusc
source share