I\'m new in Spring and want to connect spring ioc into my small(test) web-app.
I have such Servlet ProductServlet
:
public class Product
In your question you have
You cannot instantiate servlets with Spring container, they are instantiated by servlet container. You're merely declaring another instance of ProductServlet.
So, when the Servlet init()
method is called you should call
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, getServletContext());`
To inject the requestHelper declare an @Autowired
annotated field or property in your servlet:
private RequestHelper requestHelper;
@Autowired
public void setRequestHelper(RequestHelper requestHelper){
this.requestHelper = requestHelper;
}
from processInjectionBasedOnServletContext javadoc:
Process @Autowired injection for the given target object, based on the current root web application context as stored in the ServletContext.