I would like to inject a dependency into a ServletContextListener
. However, my approach is not working. I can see that Spring is calling my setter method, but l
The dogbane's answer (accepted) works but it makes testing difficult because of the way beans are instantiated. I prefere the approach suggested in this question :
@Autowired private Properties props;
@Override
public void contextInitialized(ServletContextEvent sce) {
WebApplicationContextUtils
.getRequiredWebApplicationContext(sce.getServletContext())
.getAutowireCapableBeanFactory()
.autowireBean(this);
//Do something with props
...
}