Hendy Irawan opened SPR-12430 and commented
org.springframework.context.ApplicationContextInitializer is only usable from context-param or init-param.
It should also be usable programmatically, e.g. from WebApplicationInitializer implementation:
@Override
protected WebApplicationContext createRootApplicationContext() {
final ConfigurableWebApplicationContext webAppCtx = (ConfigurableWebApplicationContext) super.createRootApplicationContext();
// this throws NullPointerException due to ServletContext not yet assigned to webAppCtx
new AppInitializer().initialize(webAppCtx);
// Ideally
webAppCtx.setInitializers(webAppCtx);
return webAppCtx;
}
Workaround:
@Override
public void onStartup(ServletContext servletContext)
throws ServletException {
// Workaround
servletContext.setInitParameter("contextInitializerClasses", AppInitializer.class.getName());
super.onStartup(servletContext);
servletContext.addListener(RequestContextListener.class);
}
Affects: 4.1.2
Issue Links: