I have the following piece of code, which I modeled on this answer:
public class DeployerServlet extends HttpServlet {
@Resource
Engine engine;
public void init(ServletConfig config) throws ServletException {
super.init(config);
SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext());
}
// ...
}
But the servlet is not even correctly instantiated. When creating an instance, Tomcat tries to look up the name com.example.DeployerServlet/engine
in JNDI which results in an exception,
SEVERE: Allocate exception for servlet Deploy Servlet
javax.naming.NameNotFoundException: Name com.example.DeployerServlet is not bound in this Context
So, what is the recommended way to inject a Spring bean into a servlet?