Qualify the Spring Shell provided ConversionService

Fixes #173
This commit is contained in:
Eric Bottard
2017-11-06 14:52:50 +01:00
parent 2ff18f9062
commit 7d50c0813f
3 changed files with 10 additions and 3 deletions

View File

@@ -44,7 +44,7 @@ import javax.validation.Validator;
public class SpringShellAutoConfiguration {
@Bean
@ConditionalOnMissingBean(ConversionService.class)
@Qualifier("spring-shell")
public ConversionService conversionService(ApplicationContext applicationContext) {
Collection<Converter> converters = applicationContext.getBeansOfType(Converter.class).values();
Collection<GenericConverter> genericConverters = applicationContext.getBeansOfType(GenericConverter.class).values();
@@ -63,6 +63,11 @@ public class SpringShellAutoConfiguration {
return defaultConversionService;
}
@Bean
public ConversionService other() {
return new DefaultConversionService();
}
@Bean
@ConditionalOnMissingBean(Validator.class)
public Validator validator() {

View File

@@ -929,7 +929,8 @@ See xref:validating-command-arguments[] for more information.
If you want to customize the `ConversionService` further, you can either
* Have the default one injected in your code and act upon it in some way
* Override it altogether with your own (custom converters will need to be registered by hand)
* Override it altogether with your own (custom converters will need to be registered by hand).
The ConversionService used by Spring Shell needs to be https://docs.spring.io/spring/docs/4.3.12.RELEASE/spring-framework-reference/htmlsingle/#beans-autowired-annotation-qualifiers[qualified] as `"spring-shell"`.
====
//==== Overriding the JLine Parser

View File

@@ -16,6 +16,7 @@
package org.springframework.shell.standard;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.ConversionService;
@@ -52,7 +53,7 @@ public class StandardAPIAutoConfiguration {
}
@Bean
public ParameterResolver standardParameterResolver(ConversionService conversionService) {
public ParameterResolver standardParameterResolver(@Qualifier("spring-shell") ConversionService conversionService) {
return new StandardParameterResolver(conversionService);
}
}