{@link BeanFactoryPostProcessor} used for bootstrapping processing of {@link Configuration @Configuration} classes.
Registered by default when using {@code context:annotation-config/} or {@code context:component-scan/}. Otherwise, may be declared manually as with any other BeanFactoryPostProcessor. This post processor is priority-ordered as it is important that any {@link Bean} methods declared in {@code @Configuration} classes have their corresponding bean definitions registered before any other {@link BeanFactoryPostProcessor} executes.
@Override publicvoidinitialize(ConfigurableApplicationContext context){ environment = context.getEnvironment(); if (isEnable()) { CompositePropertySource compositePropertySource = new CompositePropertySource(NacosConfigConstants.NACOS_BOOTSTRAP_PROPERTY_APPLICATION); CacheableEventPublishingNacosServiceFactory singleton = CacheableEventPublishingNacosServiceFactory.getSingleton(); singleton.setApplicationContext(context); String[] dataIds; String[] groupIds; String[] namespaces; try { dataIds = environment.getProperty(NacosConfigConstants.NACOS_CONFIG_DATA_ID, String[].class, new String[]{}); groupIds = environment.getProperty(NacosConfigConstants.NACOS_CONFIG_GROUP_ID, String[].class, new String[dataIds.length]); namespaces = environment.getProperty(NacosProperties.NAMESPACE, String[].class, new String[dataIds.length]);
for (int i = 0; i < dataIds.length; i ++) { Properties buildInfo = properties(namespaces[i]); ConfigService configService = singleton.createConfigService(buildInfo);
String group = StringUtils.isEmpty(groupIds[i]) ? Constants.DEFAULT_GROUP : groupIds[i]; String config = configService.getConfig(dataIds[i], group, 1000); if (config == null) { logger.error("nacos-config-spring-boot : get config failed"); continue; } String name = buildDefaultPropertySourceName(dataIds[i], groupIds[i], buildInfo); NacosPropertySource nacosPropertySource = new NacosPropertySource(name, config); compositePropertySource.addPropertySource(nacosPropertySource); } environment.getPropertySources().addFirst(compositePropertySource); } catch (NacosException e) { logger.error(e.getErrMsg()); } } }