/** * Bind the environment to the {@link SpringApplication}. * @param environment the environment to bind */ protected void bindToSpringApplication(ConfigurableEnvironment environment) { try { Binder.get(environment).bind("spring.main", Bindable.ofInstance(this)); } catch (Exception ex) { throw new IllegalStateException("Cannot bind to SpringApplication", ex); } }
private ClientProperties getClientProperties(ConditionContext context) { ClientProperties clientProperties = new ClientProperties(context.getEnvironment()); Binder.get(context.getEnvironment()).bind("spring.boot.admin.client", Bindable.ofInstance(clientProperties)); return clientProperties; } }
public static void bind(Object o, Map<String, Object> properties, String configurationPropertyName, String bindingName, Validator validator, ConversionService conversionService) { Object toBind = getTargetObject(o); new Binder(Collections.singletonList(new MapConfigurationPropertySource(properties)), null, conversionService) .bind(configurationPropertyName, Bindable.ofInstance(toBind)); if (validator != null) { BindingResult errors = new BeanPropertyBindingResult(toBind, bindingName); validator.validate(toBind, errors); if (errors.hasErrors()) { throw new RuntimeException(new BindException(errors)); } } }
@Override public <C extends AbstractConfig> void bind(String prefix, C dubboConfig) { Iterable<PropertySource<?>> propertySources = getPropertySources(); // Converts ConfigurationPropertySources Iterable<ConfigurationPropertySource> configurationPropertySources = from(propertySources); // Wrap Bindable from DubboConfig instance Bindable<C> bindable = Bindable.ofInstance(dubboConfig); Binder binder = new Binder(configurationPropertySources, new PropertySourcesPlaceholdersResolver(propertySources)); // Get BindHandler BindHandler bindHandler = getBindHandler(); // Bind binder.bind(prefix, bindable, bindHandler); }
private void bind(DataSource result) { ConfigurationPropertySource source = new MapConfigurationPropertySource( this.properties); ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases(); aliases.addAliases("url", "jdbc-url"); aliases.addAliases("username", "user"); Binder binder = new Binder(source.withAliases(aliases)); binder.bind(ConfigurationPropertyName.EMPTY, Bindable.ofInstance(result)); }
private void bindEnvironmentIfNeeded(BeanDefinitionRegistry registry) { if (!bound) { // only bind once if (this.environment == null) { this.environment = new StandardEnvironment(); } Binder.get(environment).bind("spring.cloud.refresh", Bindable.ofInstance(this)); bound = true; } }
private HostInfo getFirstNonLoopbackHostInfo(ConfigurableEnvironment environment) { InetUtilsProperties target = new InetUtilsProperties(); ConfigurationPropertySources.attach(environment); Binder.get(environment).bind(InetUtilsProperties.PREFIX, Bindable.ofInstance(target)); try (InetUtils utils = new InetUtils(target)) { return utils.findFirstNonLoopbackHostInfo(); } } }
incoming.addFirst(composite); PropertySourceBootstrapProperties remoteProperties = new PropertySourceBootstrapProperties(); Binder.get(environment(incoming)).bind("spring.cloud.config", Bindable.ofInstance(remoteProperties)); if (!remoteProperties.isAllowOverride() || (!remoteProperties.isOverrideNone() && remoteProperties.isOverrideSystemProperties())) {
private void bindEnvironmentIfNeeded(BeanDefinitionRegistry registry) { if (!bound) { // only bind once if (this.environment == null) { this.environment = new StandardEnvironment(); } Binder.get(environment).bind("spring.cloud.refresh", Bindable.ofInstance(this)); bound = true; } }
@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); } }
@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); } }
/** * 绑定参数,以下三个方法都是参考DataSourceBuilder的bind方法实现的,目的是尽量保证我们自己添加的数据源构造过程与springboot保持一致 * * @param result * @param properties */ private void bind(DataSource result, Map properties) { ConfigurationPropertySource source = new MapConfigurationPropertySource(properties); Binder binder = new Binder(new ConfigurationPropertySource[]{source.withAliases(aliases)}); // 将参数绑定到对象 binder.bind(ConfigurationPropertyName.EMPTY, Bindable.ofInstance(result)); }
@SuppressWarnings("unchecked") private void bindToDefault(String binding) { T extendedBindingPropertiesTarget = (T) BeanUtils.instantiateClass(this.getExtendedPropertiesEntryClass()); Binder binder = new Binder(ConfigurationPropertySources.get(applicationContext.getEnvironment()), new PropertySourcesPlaceholdersResolver(applicationContext.getEnvironment()), IntegrationUtils.getConversionService(applicationContext.getBeanFactory()), null); binder.bind(this.getDefaultsPrefix(), Bindable.ofInstance(extendedBindingPropertiesTarget)); this.bindings.put(binding, extendedBindingPropertiesTarget); } }
private void bindToDefault(String binding) { BindingProperties bindingPropertiesTarget = new BindingProperties(); Binder binder = new Binder(ConfigurationPropertySources.get(applicationContext.getEnvironment()), new PropertySourcesPlaceholdersResolver(applicationContext.getEnvironment()), IntegrationUtils.getConversionService(applicationContext.getBeanFactory()), null); binder.bind("spring.cloud.stream.default", Bindable.ofInstance(bindingPropertiesTarget)); this.bindings.put(binding, bindingPropertiesTarget); } }
private void bind(DataSource dataSource) { ConfigurationPropertySource source = new MapConfigurationPropertySource(this.properties); ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases(); Binder binder = new Binder(source.withAliases(aliases)); binder.bind(ConfigurationPropertyName.EMPTY, Bindable.ofInstance(dataSource)); }
private ClientProperties getClientProperties(ConditionContext context) { ClientProperties clientProperties = new ClientProperties(context.getEnvironment()); Binder.get(context.getEnvironment()).bind("spring.boot.admin.client", Bindable.ofInstance(clientProperties)); return clientProperties; } }
private HostInfo getFirstNonLoopbackHostInfo(ConfigurableEnvironment environment) { InetUtilsProperties target = new InetUtilsProperties(); ConfigurationPropertySources.attach(environment); Binder.get(environment).bind(InetUtilsProperties.PREFIX, Bindable.ofInstance(target)); try (InetUtils utils = new InetUtils(target)) { return utils.findFirstNonLoopbackHostInfo(); } } }
private void bind(XADataSource result) { ConfigurationPropertySource source = new MapConfigurationPropertySource(this.properties); ConfigurationPropertyNameAliases aliases = new ConfigurationPropertyNameAliases(); aliases.addAliases("url", "jdbc-url"); aliases.addAliases("username", "user"); Binder binder = new Binder(source.withAliases(aliases)); binder.bind(ConfigurationPropertyName.EMPTY, Bindable.ofInstance(result)); }
@Override public <C extends AbstractConfig> void bind(String prefix, C dubboConfig) { Iterable<PropertySource<?>> propertySources = getPropertySources(); // Converts ConfigurationPropertySources Iterable<ConfigurationPropertySource> configurationPropertySources = from(propertySources); // Wrap Bindable from DubboConfig instance Bindable<C> bindable = Bindable.ofInstance(dubboConfig); Binder binder = new Binder(configurationPropertySources, new PropertySourcesPlaceholdersResolver(propertySources)); // Get BindHandler BindHandler bindHandler = getBindHandler(); // Bind binder.bind(prefix, bindable, bindHandler); }
private ServiceBrokerProperties bindProperties() { ConfigurationPropertySource source = new MapConfigurationPropertySource(this.map); Binder binder = new Binder(source); ServiceBrokerProperties serviceBrokerProperties = new ServiceBrokerProperties(); binder.bind(PREFIX, Bindable.ofInstance(serviceBrokerProperties)); return serviceBrokerProperties; }