All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.javaclub.configcenter.spring.spi.DefaultConfigPropertySourcesProcessorHelper Maven / Gradle / Ivy

The newest version!
package com.github.javaclub.configcenter.spring.spi;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.Ordered;

import com.github.javaclub.configcenter.spring.annotation.JsonFormatValueProcessor;
import com.github.javaclub.configcenter.spring.annotation.SpringValueProcessor;
import com.github.javaclub.configcenter.spring.property.SpringValueDefinitionProcessor;
import com.github.javaclub.configcenter.spring.utils.BeanRegistrationUtil;

public class DefaultConfigPropertySourcesProcessorHelper implements ConfigPropertySourcesProcessorHelper {

	@Override
	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
		Map propertySourcesPlaceholderPropertyValues = new HashMap<>();
		// to make sure the default PropertySourcesPlaceholderConfigurer's priority is higher than PropertyPlaceholderConfigurer
		propertySourcesPlaceholderPropertyValues.put("order", 0);

		BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry,
				PropertySourcesPlaceholderConfigurer.class.getName(), PropertySourcesPlaceholderConfigurer.class,
				propertySourcesPlaceholderPropertyValues);
		BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, SpringValueProcessor.class.getName(),
				SpringValueProcessor.class);
		BeanRegistrationUtil.registerBeanDefinitionIfNotExists(registry, JsonFormatValueProcessor.class.getName(),
				JsonFormatValueProcessor.class);

		processSpringValueDefinition(registry);
	}

	/**
	 * For Spring 3.x versions, the BeanDefinitionRegistryPostProcessor would not be
	 * instantiated if it is added in postProcessBeanDefinitionRegistry phase, so we
	 * have to manually call the postProcessBeanDefinitionRegistry method of
	 * SpringValueDefinitionProcessor here...
	 */
	private void processSpringValueDefinition(BeanDefinitionRegistry registry) {
		SpringValueDefinitionProcessor springValueDefinitionProcessor = new SpringValueDefinitionProcessor();
		springValueDefinitionProcessor.postProcessBeanDefinitionRegistry(registry);
	}

	@Override
	public int getOrder() {
		return Ordered.LOWEST_PRECEDENCE;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy