Defer SpringBootServletInitializer getLog

Change `SpringBootServletInitializer` so that the logger is created
in `onStartup` rather than on class creation. The allows logging to
be initialized in an different WebApplicationInitializer.

Fixes gh-3704
This commit is contained in:
Phillip Webb 2015-10-14 23:35:00 -07:00
parent f02c651e40
commit e0f62308bc
1 changed files with 4 additions and 1 deletions

View File

@ -62,7 +62,7 @@ import org.springframework.web.context.WebApplicationContext;
*/
public abstract class SpringBootServletInitializer implements WebApplicationInitializer {
protected final Log logger = LogFactory.getLog(getClass());
protected Log logger; // Don't initialize early
private boolean registerErrorPageFilter = true;
@ -78,6 +78,9 @@ public abstract class SpringBootServletInitializer implements WebApplicationInit
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
// Logger initialization is deferred in case a ordered
// LogServletContextInitializer is being used
this.logger = LogFactory.getLog(getClass());
WebApplicationContext rootAppContext = createRootApplicationContext(
servletContext);
if (rootAppContext != null) {