|
16 | 16 |
|
17 | 17 | package org.springframework.shell.boot;
|
18 | 18 |
|
19 |
| -import java.util.Collection; |
20 | 19 | import java.util.Set;
|
21 | 20 |
|
22 |
| -import org.springframework.beans.factory.annotation.Qualifier; |
| 21 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
| 22 | +import org.springframework.boot.convert.ApplicationConversionService; |
23 | 23 | import org.springframework.context.ApplicationContext;
|
24 | 24 | import org.springframework.context.annotation.Bean;
|
25 | 25 | import org.springframework.context.annotation.Configuration;
|
26 | 26 | import org.springframework.context.annotation.Import;
|
27 | 27 | import org.springframework.core.convert.ConversionService;
|
28 |
| -import org.springframework.core.convert.converter.Converter; |
29 |
| -import org.springframework.core.convert.converter.ConverterFactory; |
30 |
| -import org.springframework.core.convert.converter.GenericConverter; |
31 | 28 | import org.springframework.core.convert.support.DefaultConversionService;
|
| 29 | +import org.springframework.format.support.FormattingConversionService; |
32 | 30 | import org.springframework.shell.CommandRegistry;
|
33 | 31 | import org.springframework.shell.ResultHandler;
|
34 | 32 | import org.springframework.shell.ResultHandlerService;
|
|
44 | 42 | public class SpringShellAutoConfiguration {
|
45 | 43 |
|
46 | 44 | @Bean
|
47 |
| - @Qualifier("spring-shell") |
| 45 | + @ConditionalOnMissingBean(ConversionService.class) |
48 | 46 | public ConversionService shellConversionService(ApplicationContext applicationContext) {
|
49 |
| - Collection<Converter> converters = applicationContext.getBeansOfType(Converter.class).values(); |
50 |
| - Collection<GenericConverter> genericConverters = applicationContext.getBeansOfType(GenericConverter.class).values(); |
51 |
| - Collection<ConverterFactory> converterFactories = applicationContext.getBeansOfType(ConverterFactory.class).values(); |
52 |
| - |
53 |
| - DefaultConversionService defaultConversionService = new DefaultConversionService(); |
54 |
| - for (Converter converter : converters) { |
55 |
| - defaultConversionService.addConverter(converter); |
56 |
| - } |
57 |
| - for (GenericConverter genericConverter : genericConverters) { |
58 |
| - defaultConversionService.addConverter(genericConverter); |
59 |
| - } |
60 |
| - for (ConverterFactory converterFactory : converterFactories) { |
61 |
| - defaultConversionService.addConverterFactory(converterFactory); |
62 |
| - } |
63 |
| - return defaultConversionService; |
| 47 | + FormattingConversionService service = new FormattingConversionService(); |
| 48 | + DefaultConversionService.addDefaultConverters(service); |
| 49 | + DefaultConversionService.addCollectionConverters(service); |
| 50 | + ApplicationConversionService.addBeans(service, applicationContext); |
| 51 | + return service; |
64 | 52 | }
|
65 | 53 |
|
66 | 54 | @Bean
|
|
0 commit comments