Java Code Examples for org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver

The following examples show how to use org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver. These examples are extracted from open source projects. 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
@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
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 3
@SuppressWarnings("unchecked")
private void bindToDefault(String binding) {
	T extendedBindingPropertiesTarget = (T) BeanUtils
			.instantiateClass(this.getExtendedPropertiesEntryClass());
	Binder binder = new Binder(
			ConfigurationPropertySources
					.get(this.applicationContext.getEnvironment()),
			new PropertySourcesPlaceholdersResolver(
					this.applicationContext.getEnvironment()),
			IntegrationUtils.getConversionService(
					this.applicationContext.getBeanFactory()),
			null);
	binder.bind(this.getDefaultsPrefix(),
			Bindable.ofInstance(extendedBindingPropertiesTarget));
	this.bindings.put(binding, extendedBindingPropertiesTarget);
}
 
Example 4
public FunctionalConfigurationPropertiesBinder(ConfigurableApplicationContext context) {
	PropertySources propertySources = new FunctionalPropertySourcesDeducer(context).getPropertySources();
	this.context = context;
	this.binder = new Binder(ConfigurationPropertySources.from(propertySources),
       				new PropertySourcesPlaceholdersResolver(propertySources),
       				null,
			(registry) -> context.getBeanFactory().copyRegisteredEditorsTo(registry));
}
 
Example 5
@Bean
@ConfigurationProperties(prefix = "spring.cloud.stream.kafka.streams.binder")
public KafkaStreamsBinderConfigurationProperties binderConfigurationProperties(
		KafkaProperties kafkaProperties, ConfigurableEnvironment environment,
		BindingServiceProperties properties, ConfigurableApplicationContext context) throws Exception {
	final Map<String, BinderConfiguration> binderConfigurations = getBinderConfigurations(
			properties);
	for (Map.Entry<String, BinderConfiguration> entry : binderConfigurations
			.entrySet()) {
		final BinderConfiguration binderConfiguration = entry.getValue();
		final String binderType = binderConfiguration.getBinderType();
		if (binderType != null && (binderType.equals(KSTREAM_BINDER_TYPE)
				|| binderType.equals(KTABLE_BINDER_TYPE)
				|| binderType.equals(GLOBALKTABLE_BINDER_TYPE))) {
			Map<String, Object> binderProperties = new HashMap<>();
			this.flatten(null, binderConfiguration.getProperties(), binderProperties);
			environment.getPropertySources().addFirst(
					new MapPropertySource(entry.getKey() + "-kafkaStreamsBinderEnv", binderProperties));

			Binder binder = new Binder(ConfigurationPropertySources.get(environment),
					new PropertySourcesPlaceholdersResolver(environment),
					IntegrationUtils.getConversionService(context.getBeanFactory()), null);
			final Constructor<KafkaStreamsBinderConfigurationProperties> kafkaStreamsBinderConfigurationPropertiesConstructor =
					ReflectionUtils.accessibleConstructor(KafkaStreamsBinderConfigurationProperties.class, KafkaProperties.class);
			final KafkaStreamsBinderConfigurationProperties kafkaStreamsBinderConfigurationProperties =
					BeanUtils.instantiateClass(kafkaStreamsBinderConfigurationPropertiesConstructor, kafkaProperties);
			final BindResult<KafkaStreamsBinderConfigurationProperties> bind = binder.bind("spring.cloud.stream.kafka.streams.binder", Bindable.ofInstance(kafkaStreamsBinderConfigurationProperties));
			context.getBeanFactory().registerSingleton(
					entry.getKey() + "-KafkaStreamsBinderConfigurationProperties",
					bind.get());
		}
	}
	return new KafkaStreamsBinderConfigurationProperties(kafkaProperties);
}
 
Example 6
Source Project: riptide   Source File: RiptidePostProcessor.java    License: MIT License 5 votes vote down vote up
@Override
public void setEnvironment(final Environment environment) {
    final Iterable<ConfigurationPropertySource> sources =
            from(((ConfigurableEnvironment) environment).getPropertySources());
    final Binder binder = new Binder(sources,
            new PropertySourcesPlaceholdersResolver(environment));

    this.properties = Defaulting.withDefaults(binder.bindOrCreate("riptide", RiptideProperties.class));
}
 
Example 7
private void bindToDefault(String binding) {
	BindingProperties bindingPropertiesTarget = new BindingProperties();
	Binder binder = new Binder(
			ConfigurationPropertySources
					.get(this.applicationContext.getEnvironment()),
			new PropertySourcesPlaceholdersResolver(
					this.applicationContext.getEnvironment()),
			IntegrationUtils.getConversionService(
					this.applicationContext.getBeanFactory()),
			null);
	binder.bind("spring.cloud.stream.default",
			Bindable.ofInstance(bindingPropertiesTarget));
	this.bindings.put(binding, bindingPropertiesTarget);
}
 
Example 8
private PropertySourcesPlaceholdersResolver getPropertySourcesPlaceholdersResolver() {
  return new PropertySourcesPlaceholdersResolver(this.propertySources);
}
 
Example 9
private static PropertySourcesPlaceholdersResolver getPropertySourcesPlaceholdersResolver(PropertySources propertySources) {
    return new PropertySourcesPlaceholdersResolver(propertySources);
}