Java Code Examples for org.springframework.boot.context.properties.bind.BindResult#isBound()

The following examples show how to use org.springframework.boot.context.properties.bind.BindResult#isBound() . 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: SpringdocBeanFactoryConfigurer.java    From springdoc-openapi with Apache License 2.0 6 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)  {
	final BindResult<SpringDocConfigProperties> result = Binder.get(environment)
			.bind(SPRINGDOC_PREFIX, SpringDocConfigProperties.class);
	if (result.isBound()) {
		SpringDocConfigProperties springDocGroupConfig = result.get();
		List<GroupedOpenApi> groupedOpenApis = springDocGroupConfig.getGroupConfigs().stream()
				.map(elt -> {
					GroupedOpenApi.Builder builder = GroupedOpenApi.builder();
					if (!CollectionUtils.isEmpty(elt.getPackagesToScan()))
						builder.packagesToScan(elt.getPackagesToScan().toArray(new String[0]));
					if (!CollectionUtils.isEmpty(elt.getPathsToMatch()))
						builder.pathsToMatch(elt.getPathsToMatch().toArray(new String[0]));
					return builder.group(elt.getGroup()).build();
				})
				.collect(Collectors.toList());
		groupedOpenApis.forEach(elt -> beanFactory.registerSingleton(elt.getGroup(), elt));
	}
	initBeanFactoryPostProcessor(beanFactory);
}
 
Example 2
Source File: OSSCondition.java    From jeecg-boot-with-activiti with MIT License 6 votes vote down vote up
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
	String sourceClass = "";
	if (metadata instanceof ClassMetadata) {
		sourceClass = ((ClassMetadata) metadata).getClassName();
	}
	ConditionMessage.Builder message = ConditionMessage.forCondition("OSS", sourceClass);
	Environment environment = context.getEnvironment();
	try {
		BindResult<OSSType> specified = Binder.get(environment).bind("oss.type", OSSType.class);
		if (!specified.isBound()) {
			return ConditionOutcome.match(message.because("automatic OSS type"));
		}
		OSSType required = OSSConfigurations.getType(((AnnotationMetadata) metadata).getClassName());
		if (specified.get() == required) {
			return ConditionOutcome.match(message.because(specified.get() + " OSS type"));
		}
	}
	catch (BindException ex) {
	}
	return ConditionOutcome.noMatch(message.because("unknown OSS type"));
}
 
Example 3
Source File: EncodingDecodingBindAdviceHandler.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: BindingHandlerAdvise.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@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 5
Source File: ApplicationMetricsProperties.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
private Map<String, String> bindProperties() {
	Map<String, String> target;
	BindResult<Map<String, String>> bindResult = Binder.get(this.environment).bind("",
			STRING_STRING_MAP);
	if (bindResult.isBound()) {
		target = bindResult.get();
	}
	else {
		target = new HashMap<>();
	}
	return target;
}