Commit 19ce0aa4 authored by Phillip Webb's avatar Phillip Webb

Refine BackgroundPreinitializer

Update `BackgroundPreinitializer` to start initialization earlier. Also
refine the startup order and initialize Charsets.

Fixes gh-11570
See gh-11412
parent 79fc8838
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -16,16 +16,19 @@
package org.springframework.boot.autoconfigure;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.validation.Configuration;
import javax.validation.Validation;
import org.apache.catalina.mbeans.MBeanFactory;
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.context.event.ApplicationFailedEvent;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.boot.context.event.ApplicationStartingEvent;
import org.springframework.boot.context.event.SpringApplicationEvent;
import org.springframework.boot.context.logging.LoggingApplicationListener;
import org.springframework.context.ApplicationListener;
......@@ -53,7 +56,7 @@ public class BackgroundPreinitializer
@Override
public void onApplicationEvent(SpringApplicationEvent event) {
if (event instanceof ApplicationEnvironmentPreparedEvent) {
if (event instanceof ApplicationStartingEvent) {
if (preinitializationStarted.compareAndSet(false, true)) {
performPreinitialization();
}
......@@ -76,11 +79,12 @@ public class BackgroundPreinitializer
@Override
public void run() {
runSafely(new ConversionServiceInitializer());
runSafely(new ValidationInitializer());
runSafely(new MessageConverterInitializer());
runSafely(new MBeanFactoryInitializer());
runSafely(new ValidationInitializer());
runSafely(new JacksonInitializer());
runSafely(new ConversionServiceInitializer());
runSafely(new CharsetInitializer());
preinitializationComplete.countDown();
}
......@@ -135,7 +139,8 @@ public class BackgroundPreinitializer
@Override
public void run() {
Validation.byDefaultProvider().configure().buildValidatorFactory();
Configuration<?> configuration = Validation.byDefaultProvider().configure();
configuration.buildValidatorFactory().getValidator();
}
}
......@@ -164,4 +169,14 @@ public class BackgroundPreinitializer
}
private static class CharsetInitializer implements Runnable {
@Override
public void run() {
StandardCharsets.UTF_8.name();
Charset.availableCharsets();
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment