org.springframework.boot.context.properties.bind.BindHandler Java Examples
The following examples show how to use
org.springframework.boot.context.properties.bind.BindHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BinderDubboConfigBinder.java From dubbo-spring-boot-project with Apache License 2.0 | 6 votes |
@Override public void bind(Map<String, Object> configurationProperties, boolean ignoreUnknownFields, boolean ignoreInvalidFields, Object configurationBean) { Iterable<PropertySource<?>> propertySources = asList(new MapPropertySource("internal", configurationProperties)); // Converts ConfigurationPropertySources Iterable<ConfigurationPropertySource> configurationPropertySources = from(propertySources); // Wrap Bindable from DubboConfig instance Bindable bindable = Bindable.ofInstance(configurationBean); Binder binder = new Binder(configurationPropertySources, new PropertySourcesPlaceholdersResolver(propertySources)); // Get BindHandler BindHandler bindHandler = getBindHandler(ignoreUnknownFields, ignoreInvalidFields); // Bind binder.bind("", bindable, bindHandler); }
Example #2
Source File: EncodingDecodingBindAdviceHandler.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 6 votes |
@Override public BindHandler apply(BindHandler bindHandler) { BindHandler handler = new AbstractBindHandler(bindHandler) { @Override public <T> Bindable<T> onStart(ConfigurationPropertyName name, Bindable<T> target, BindContext context) { final String configName = name.toString(); if (configName.contains("use") && configName.contains("native") && (configName.contains("encoding") || configName.contains("decoding"))) { BindResult<T> result = context.getBinder().bind(name, target); if (result.isBound()) { if (configName.contains("encoding")) { EncodingDecodingBindAdviceHandler.this.encodingSettingProvided = true; } else { EncodingDecodingBindAdviceHandler.this.decodingSettingProvided = true; } return target.withExistingValue(result.get()); } } return bindHandler.onStart(name, target, context); } }; return handler; }
Example #3
Source File: ConfigurationService.java From spring-cloud-gateway with Apache License 2.0 | 6 votes |
static <T> T bindOrCreate(Bindable<T> bindable, Map<String, Object> properties, String configurationPropertyName, Validator validator, ConversionService conversionService) { // see ConfigurationPropertiesBinder from spring boot for this definition. BindHandler handler = new IgnoreTopLevelConverterNotFoundBindHandler(); if (validator != null) { // TODO: list of validators? handler = new ValidationBindHandler(handler, validator); } List<ConfigurationPropertySource> propertySources = Collections .singletonList(new MapConfigurationPropertySource(properties)); return new Binder(propertySources, null, conversionService) .bindOrCreate(configurationPropertyName, bindable, handler); }
Example #4
Source File: JasyptEncryptorConfigurationProperties.java From jasypt-spring-boot with MIT License | 6 votes |
public static JasyptEncryptorConfigurationProperties bindConfigProps(ConfigurableEnvironment environment) { final BindHandler handler = new IgnoreErrorsBindHandler(BindHandler.DEFAULT); final MutablePropertySources propertySources = environment.getPropertySources(); final Binder binder = new Binder(ConfigurationPropertySources.from(propertySources), new PropertySourcesPlaceholdersResolver(propertySources), ApplicationConversionService.getSharedInstance()); final JasyptEncryptorConfigurationProperties config = new JasyptEncryptorConfigurationProperties(); final ResolvableType type = ResolvableType.forClass(JasyptEncryptorConfigurationProperties.class); final Annotation annotation = AnnotationUtils.findAnnotation(JasyptEncryptorConfigurationProperties.class, ConfigurationProperties.class); final Annotation[] annotations = new Annotation[]{annotation}; final Bindable<?> target = Bindable.of(type).withExistingValue(config).withAnnotations(annotations); binder.bind("jasypt.encryptor", target, handler); return config; }
Example #5
Source File: GenericPropertiesConfiguration.java From camunda-bpm-spring-boot-starter with Apache License 2.0 | 6 votes |
@Override public void preInit(SpringProcessEngineConfiguration springProcessEngineConfiguration) { GenericProperties genericProperties = camundaBpmProperties.getGenericProperties(); final Map<String, Object> properties = genericProperties.getProperties(); if (!CollectionUtils.isEmpty(properties)) { ConfigurationPropertySource source = new MapConfigurationPropertySource(properties); Binder binder = new Binder(source); try { if (genericProperties.isIgnoreUnknownFields()) { binder.bind(ConfigurationPropertyName.EMPTY, Bindable.ofInstance(springProcessEngineConfiguration)); } else { binder.bind(ConfigurationPropertyName.EMPTY, Bindable.ofInstance(springProcessEngineConfiguration), new NoUnboundElementsBindHandler(BindHandler.DEFAULT)); } } catch (Exception e) { throw LOG.exceptionDuringBinding(e.getMessage()); } logger.debug("properties bound to configuration: {}", genericProperties); } }
Example #6
Source File: BindingHandlerAdvise.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Override public BindHandler apply(BindHandler bindHandler) { BindHandler handler = new AbstractBindHandler(bindHandler) { @Override public <T> Bindable<T> onStart(ConfigurationPropertyName name, Bindable<T> target, BindContext context) { ConfigurationPropertyName defaultName = getDefaultName(name); if (defaultName != null) { BindResult<T> result = context.getBinder().bind(defaultName, target); if (result.isBound()) { return target.withExistingValue(result.get()); } } return bindHandler.onStart(name, target, context); } }; return handler; }
Example #7
Source File: GenericPropertiesConfiguration.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Override public void preInit(SpringProcessEngineConfiguration springProcessEngineConfiguration) { GenericProperties genericProperties = camundaBpmProperties.getGenericProperties(); final Map<String, Object> properties = genericProperties.getProperties(); if (!CollectionUtils.isEmpty(properties)) { ConfigurationPropertySource source = new MapConfigurationPropertySource(properties); Binder binder = new Binder(source); try { if (genericProperties.isIgnoreUnknownFields()) { binder.bind(ConfigurationPropertyName.EMPTY, Bindable.ofInstance(springProcessEngineConfiguration)); } else { binder.bind(ConfigurationPropertyName.EMPTY, Bindable.ofInstance(springProcessEngineConfiguration), new NoUnboundElementsBindHandler(BindHandler.DEFAULT)); } } catch (Exception e) { throw LOG.exceptionDuringBinding(e.getMessage()); } logger.debug("properties bound to configuration: {}", genericProperties); } }
Example #8
Source File: MangoConfigFactory.java From mango-spring-boot-starter with Apache License 2.0 | 5 votes |
/** * 获取配置 * * @param beanFactory beanFactory * @param prefix 前缀 * @return */ public static MangoConfig getMangoConfig(DefaultListableBeanFactory beanFactory, String prefix) { MangoConfig config = new MangoConfig(); Bindable<?> target = Bindable.ofInstance(config); PropertySources propertySources = getPropertySources(beanFactory); BindHandler bindHandler = getBindHandler(); BindResult configBindResult = getBinder(propertySources, beanFactory).bind(prefix, target, bindHandler); return (MangoConfig) configBindResult.get(); }
Example #9
Source File: CustomizedConfigurationPropertiesBinder.java From apollo-use-cases with Apache License 2.0 | 4 votes |
public void bind(String configPrefix, Bindable<?> bean) { BindHandler handler = new IgnoreTopLevelConverterNotFoundBindHandler(); this.binder.bind(configPrefix, bean, handler); }
Example #10
Source File: MangoConfigFactory.java From mango-spring-boot-starter with Apache License 2.0 | 4 votes |
private static BindHandler getBindHandler() { BindHandler handler = new ThrowErrorBindHandler(); return handler; }
Example #11
Source File: ThrowErrorBindHandler.java From mango-spring-boot-starter with Apache License 2.0 | 4 votes |
public ThrowErrorBindHandler(BindHandler parent) { super(parent); }