What is the best way to inject dependencies into Servlets when you don’t want to use any sort of DI frameworks? Shall I put them into the ServletContext in a ServletContextListener?
What is the best way to inject dependencies into Servlets when you don’t want
Share
Yes. You could initialize them in a
ServletContextListener(if you need them pre-initialized) and then put them into theServletContextfor all your servlets to access.It’s probably best to store the objects by their class name so retrieval is type-safe.