Restore conversion service binary compatibility

Change `ApplicationConversionService.getSharedInstance()` to again
return a `ConversionService` rather than `ApplicationConversionService`.

This restore binary compatibly with Spring Boot 2.0

Closes gh-14938
pull/14950/head
Phillip Webb 6 years ago
parent 2097b6a4c1
commit 99e166516d

@ -59,6 +59,8 @@ import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.GenericApplicationContext; import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.GenericTypeResolver; import org.springframework.core.GenericTypeResolver;
import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.ConfigurableConversionService;
import org.springframework.core.env.CommandLinePropertySource; import org.springframework.core.env.CommandLinePropertySource;
import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.CompositePropertySource;
import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.ConfigurableEnvironment;
@ -480,8 +482,10 @@ public class SpringApplication {
protected void configureEnvironment(ConfigurableEnvironment environment, protected void configureEnvironment(ConfigurableEnvironment environment,
String[] args) { String[] args) {
if (this.addConversionService) { if (this.addConversionService) {
ConversionService conversionService = ApplicationConversionService
.getSharedInstance();
environment.setConversionService( environment.setConversionService(
ApplicationConversionService.getSharedInstance()); (ConfigurableConversionService) conversionService);
} }
configurePropertySources(environment, args); configurePropertySources(environment, args);
configureProfiles(environment, args); configureProfiles(environment, args);

@ -53,12 +53,16 @@ public class ApplicationConversionService extends FormattingConversionService {
} }
/** /**
* Return a shared default {@code ApplicationConversionService} instance, lazily * Return a shared default application {@code ConversionService} instance, lazily
* building it once needed. * building it once needed.
* <p>
* Note: This method actually returns an {@link ApplicationConversionService}
* instance. However, the {@code ConversionService} signature has been preserved for
* binary compatibility.
* @return the shared {@code ApplicationConversionService} instance (never * @return the shared {@code ApplicationConversionService} instance (never
* {@code null}) * {@code null})
*/ */
public static ApplicationConversionService getSharedInstance() { public static ConversionService getSharedInstance() {
ApplicationConversionService sharedInstance = ApplicationConversionService.sharedInstance; ApplicationConversionService sharedInstance = ApplicationConversionService.sharedInstance;
if (sharedInstance == null) { if (sharedInstance == null) {
synchronized (ApplicationConversionService.class) { synchronized (ApplicationConversionService.class) {

Loading…
Cancel
Save