@Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof DruidDataSource) { // 设置 Druid 名称 ((DruidDataSource) bean).setName(beanName); // 将 'spring.datasource.druid.data-sources.${name}' 的配置绑定到 Bean if (!resolver.getSubProperties(EMPTY).isEmpty()) { PropertySourcesBinder binder = new PropertySourcesBinder(environment); binder.bindTo(PREFIX + beanName, bean); } // 用户自定义配置 if (customizers != null && !customizers.isEmpty()) { for (DruidDataSourceCustomizer customizer : customizers) { customizer.customize((DruidDataSource) bean); } } boolean isSingle = BEAN_NAME.equals(beanName); if (isSingle) { log.debug("druid data-source init..."); } else { log.debug("druid {}-data-source init...", beanName); } } return bean; }
GitFullInfoContributor(Resource location) throws BindException, IOException { if (location.exists()) { Properties gitInfoProperties = PropertiesLoaderUtils .loadProperties(location); PropertiesPropertySource gitPropertySource = new PropertiesPropertySource( "git", gitInfoProperties); this.content = new PropertySourcesBinder(gitPropertySource) .extractAll("git"); } }
public EnvironmentInfoContributor(ConfigurableEnvironment environment) { this.binder = new PropertySourcesBinder(environment); }
/** * Extract the raw content based on the specified {@link PropertySource}. * @param propertySource the property source to use * @return the raw content */ protected Map<String, Object> extractContent(PropertySource<?> propertySource) { return new PropertySourcesBinder(propertySource).extractAll(""); }