Java Code Examples for org.springframework.boot.context.properties.ConfigurationProperties#prefix()

The following examples show how to use org.springframework.boot.context.properties.ConfigurationProperties#prefix() . 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: ConfigurationPropertiesDestructionRebindingHelper.java    From spring-cloud-formula with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessBeforeDestruction(Object bean, String name) throws BeansException {
    if (environment == null) {
        return;
    }

    Object target = bean;
    if (AopUtils.isAopProxy(bean)) {
        target = ProxyUtils.getTargetObject(target);
    }

    if (AnnotationUtils.findAnnotation(target.getClass(), ConfigurationProperties.class) == null) {
        return;
    }

    try {
        target.getClass().getConstructor();
    } catch (NoSuchMethodException e) {
        logger.debug("can not found default constructor, skip it");
        return;
    }

    try {
        ConfigurationProperties annotation = AnnotationUtils.findAnnotation(
                target.getClass(), ConfigurationProperties.class);
        String prefix = annotation.prefix();
        Object result = Binder.get(environment).bind(prefix, (Class) target.getClass()).orElseCreate(target.getClass());
        BeanUtils.copyProperties(result, target);
    } catch (Throwable t) {
        logger.warn("error while process destruction bean with name: {}", name, t);
    }
}
 
Example 2
Source File: PropertiesConsistencyTest.java    From ogham with Apache License 2.0 5 votes vote down vote up
private ConfigurationPropertiesMetadata toConfigurationPropertiesBean(Entry<String, Object> entry) {
	ConfigurationProperties annotation = entry.getValue().getClass().getAnnotation(ConfigurationProperties.class);
	if (annotation == null) {
		return null;
	}
	String prefix = annotation.prefix();
	if (prefix == null || prefix.isEmpty()) {
		prefix = annotation.value();
	}
	if (prefix == null) {
		return null;
	}
	return new ConfigurationPropertiesMetadata(entry.getKey(), entry.getValue(), prefix);
}