Search in sources :

Example 1 with ApplicationConversionService

use of org.springframework.boot.convert.ApplicationConversionService in project spring-boot by spring-projects.

the class EndpointAutoConfiguration method createConversionService.

private ConversionService createConversionService(List<Converter<?, ?>> converters, List<GenericConverter> genericConverters) {
    if (genericConverters.isEmpty() && converters.isEmpty()) {
        return ApplicationConversionService.getSharedInstance();
    }
    ApplicationConversionService conversionService = new ApplicationConversionService();
    converters.forEach(conversionService::addConverter);
    genericConverters.forEach(conversionService::addConverter);
    return conversionService;
}
Also used : ApplicationConversionService(org.springframework.boot.convert.ApplicationConversionService)

Example 2 with ApplicationConversionService

use of org.springframework.boot.convert.ApplicationConversionService in project spring-boot by spring-projects.

the class SpringApplication method configureEnvironment.

/**
 * Template method delegating to
 * {@link #configurePropertySources(ConfigurableEnvironment, String[])} and
 * {@link #configureProfiles(ConfigurableEnvironment, String[])} in that order.
 * Override this method for complete control over Environment customization, or one of
 * the above for fine-grained control over property sources or profiles, respectively.
 * @param environment this application's environment
 * @param args arguments passed to the {@code run} method
 * @see #configureProfiles(ConfigurableEnvironment, String[])
 * @see #configurePropertySources(ConfigurableEnvironment, String[])
 */
protected void configureEnvironment(ConfigurableEnvironment environment, String[] args) {
    if (this.addConversionService) {
        environment.setConversionService(new ApplicationConversionService());
    }
    configurePropertySources(environment, args);
    configureProfiles(environment, args);
}
Also used : ApplicationConversionService(org.springframework.boot.convert.ApplicationConversionService)

Example 3 with ApplicationConversionService

use of org.springframework.boot.convert.ApplicationConversionService in project spring-boot by spring-projects.

the class ConversionServiceDeducerTests method getConversionServiceWhenHasNoConversionServiceBeanAndNoQualifiedBeansAndBeanFactoryConversionServiceContainsOnlyBeanFactoryInstance.

@Test
void getConversionServiceWhenHasNoConversionServiceBeanAndNoQualifiedBeansAndBeanFactoryConversionServiceContainsOnlyBeanFactoryInstance() {
    ConfigurableApplicationContext applicationContext = new AnnotationConfigApplicationContext(EmptyConfiguration.class);
    ConversionService conversionService = new ApplicationConversionService();
    applicationContext.getBeanFactory().setConversionService(conversionService);
    ConversionServiceDeducer deducer = new ConversionServiceDeducer(applicationContext);
    List<ConversionService> conversionServices = deducer.getConversionServices();
    assertThat(conversionServices).containsOnly(conversionService);
    assertThat(conversionServices.get(0)).isSameAs(conversionService);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ApplicationConversionService(org.springframework.boot.convert.ApplicationConversionService) ConversionService(org.springframework.core.convert.ConversionService) ApplicationConversionService(org.springframework.boot.convert.ApplicationConversionService) Test(org.junit.jupiter.api.Test)

Example 4 with ApplicationConversionService

use of org.springframework.boot.convert.ApplicationConversionService in project spring-boot by spring-projects.

the class ConversionServiceDeducer method getConversionServices.

private List<ConversionService> getConversionServices(ConfigurableApplicationContext applicationContext) {
    List<ConversionService> conversionServices = new ArrayList<>();
    if (applicationContext.getBeanFactory().getConversionService() != null) {
        conversionServices.add(applicationContext.getBeanFactory().getConversionService());
    }
    ConverterBeans converterBeans = new ConverterBeans(applicationContext);
    if (!converterBeans.isEmpty()) {
        ApplicationConversionService beansConverterService = new ApplicationConversionService();
        converterBeans.addTo(beansConverterService);
        conversionServices.add(beansConverterService);
    }
    return conversionServices;
}
Also used : ApplicationConversionService(org.springframework.boot.convert.ApplicationConversionService) ConversionService(org.springframework.core.convert.ConversionService) ArrayList(java.util.ArrayList) ApplicationConversionService(org.springframework.boot.convert.ApplicationConversionService)

Aggregations

ApplicationConversionService (org.springframework.boot.convert.ApplicationConversionService)4 ConversionService (org.springframework.core.convert.ConversionService)2 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1