Skip to content

Commit 6cc6a15

Browse files
committed
Polish 'Refine BackgroundPreinitializer Jackson initialization'
See gh-33220
1 parent bdac416 commit 6cc6a15

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/BackgroundPreinitializer.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.springframework.format.support.DefaultFormattingConversionService;
3535
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
3636
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
37-
import org.springframework.util.ClassUtils;
3837

3938
/**
4039
* {@link ApplicationListener} to trigger early initialization in a background thread of
@@ -101,24 +100,22 @@ private void performPreinitialization() {
101100
public void run() {
102101
runSafely(new ConversionServiceInitializer());
103102
runSafely(new ValidationInitializer());
104-
if (ClassUtils.isPresent(
105-
"org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter",
106-
BackgroundPreinitializer.class.getClassLoader())) {
107-
runSafely(new MessageConverterInitializer());
108-
}
109-
else {
103+
if (!runSafely(new MessageConverterInitializer())) {
104+
// If the MessageConverterInitializer we still might be able to
105+
// initialize Jackson
110106
runSafely(new JacksonInitializer());
111107
}
112108
runSafely(new CharsetInitializer());
113109
preinitializationComplete.countDown();
114110
}
115111

116-
public void runSafely(Runnable runnable) {
112+
boolean runSafely(Runnable runnable) {
117113
try {
118114
runnable.run();
115+
return true;
119116
}
120117
catch (Throwable ex) {
121-
// Ignore
118+
return false;
122119
}
123120
}
124121

0 commit comments

Comments
 (0)