Корректное использование Binder Spring Boot 2

На версии 'springBoot: 1.5.8.RELEASE',

Реализация связывания отрабатывала успешно

    // T target - передаваемый экземпляр бина класса с нужными свойствами
    ConfigurableEnvironment environment; // бин
    PropertySources propertySources = environment.getPropertySources();
        private static <T> void bind(String prefix, T target, PropertySources propertySources) throws BindException {
                org.springframework.boot.bind.PropertiesConfigurationFactory<T> configurationFactory = new PropertiesConfigurationFactory<>(target);
                configurationFactory.setTargetName(prefix);
                configurationFactory.setPropertySources(propertySources);
                configurationFactory.setResolvePlaceholders(true);
                configurationFactory.bindPropertiesToTarget();
            }

на версии springBoot: '2.2.4.RELEASE пытаюсь сделать через org.springframework.boot.context.properties.bind.Binder

private static <T> void bind(String prefix, T target, PropertySources propertySources) {
        new Binder((ConfigurationPropertySource) propertySources).bind(prefix, YotaImportJobConfig.class);
    }

но не понятно куда тут прикрепить target. и получаю ошибку при build

java.lang.ClassCastException: class org.springframework.core.env.MutablePropertySources cannot be cast to class org.springframework.boot.context.properties.source.ConfigurationPropertySource

Ответы (0 шт):