Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@
import com.alibaba.cloud.nacos.refresh.NacosRefreshHistory;

import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

import static com.alibaba.cloud.nacos.constants.Constants.SPRING_CONFIG_IMPORT_PROPERTIES;

/**
* @author juven.xuxb
* @author freeman
Expand All @@ -40,8 +36,6 @@
@Conditional(NacosConfigEnabledCondition.class)
public class NacosConfigAutoConfiguration {



@Bean
@ConditionalOnMissingBean(value = NacosConfigProperties.class, search = SearchStrategy.CURRENT)
public NacosConfigProperties nacosConfigProperties(ApplicationContext context) {
Expand All @@ -63,19 +57,16 @@ public NacosRefreshHistory nacosRefreshHistory() {
}

@Bean
@ConditionalOnProperty(name = SPRING_CONFIG_IMPORT_PROPERTIES)
public NacosConfigManager nacosConfigManager(NacosConfigProperties nacosConfigProperties) {
return NacosConfigManager.getInstance(nacosConfigProperties);
}

@Bean
@ConditionalOnBean(NacosConfigManager.class)
public static NacosAnnotationProcessor nacosAnnotationProcessor() {
return new NacosAnnotationProcessor();
}

@Bean
@ConditionalOnBean(NacosConfigManager.class)
public NacosContextRefresher nacosContextRefresher(NacosConfigManager nacosConfigManager,
NacosRefreshHistory nacosRefreshHistory) {
// Consider that it is not necessary to be compatible with the previous
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@
package com.alibaba.cloud.nacos;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

import static com.alibaba.cloud.nacos.constants.Constants.SPRING_CONFIG_IMPORT_PROPERTIES;

/**
* @author xiaojing
* @author freeman
Expand All @@ -40,7 +37,6 @@ public NacosConfigProperties nacosConfigProperties() {

@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(name = SPRING_CONFIG_IMPORT_PROPERTIES)
public NacosConfigManager nacosConfigManager(
NacosConfigProperties nacosConfigProperties) {
return new NacosConfigManager(nacosConfigProperties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,7 @@ public ConfigData load(ConfigDataLoaderContext context,
public ConfigData doLoad(ConfigDataLoaderContext context,
NacosConfigDataResource resource) {
try {
NacosConfigManager nacosConfigManager;
try {
nacosConfigManager = getBean(context, NacosConfigManager.class);
}
catch (Exception ignore) {
if (log.isErrorEnabled()) {
log.error("Error getting properties from nacos cause nacosConfigManager is not registration on spring context");
}
return null;
}
ConfigService configService = nacosConfigManager
ConfigService configService = getBean(context, NacosConfigManager.class)
.getConfigService();
NacosConfigProperties properties = getBean(context,
NacosConfigProperties.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.springframework.core.Ordered;

import static com.alibaba.cloud.nacos.configdata.NacosConfigDataResource.NacosItemConfig;
import static com.alibaba.cloud.nacos.constants.Constants.SPRING_CONFIG_IMPORT_PROPERTIES;

/**
* Implementation of {@link ConfigDataLocationResolver}, load Nacos
Expand Down Expand Up @@ -118,7 +117,7 @@ protected Log getLog() {

@Override
public boolean isResolvable(ConfigDataLocationResolverContext context,
ConfigDataLocation location) {
ConfigDataLocation location) {
if (!location.hasPrefix(getPrefix())) {
return false;
}
Expand Down Expand Up @@ -154,7 +153,7 @@ public List<NacosConfigDataResource> resolveProfileSpecific(
bootstrapContext.registerIfAbsent(NacosConfigProperties.class,
BootstrapRegistry.InstanceSupplier.of(properties));

registerConfigManager(properties, bootstrapContext, resolverContext);
registerConfigManager(properties, bootstrapContext);

return loadConfigDataResources(location, profiles, properties);
}
Expand Down Expand Up @@ -197,11 +196,8 @@ private URI getUri(ConfigDataLocation location, NacosConfigProperties properties
}

private void registerConfigManager(NacosConfigProperties properties,
ConfigurableBootstrapContext bootstrapContext,
ConfigDataLocationResolverContext resolverContext) {
List<?> springConfigImportProperties = resolverContext.getBinder()
.bind(SPRING_CONFIG_IMPORT_PROPERTIES, List.class).get();
if (!springConfigImportProperties.isEmpty() && !bootstrapContext.isRegistered(NacosConfigManager.class)) {
ConfigurableBootstrapContext bootstrapContext) {
if (!bootstrapContext.isRegistered(NacosConfigManager.class)) {
bootstrapContext.register(NacosConfigManager.class,
BootstrapRegistry.InstanceSupplier.of(NacosConfigManager.getInstance(properties)));
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

package com.alibaba.cloud.nacos.proxy.druid;

import com.alibaba.cloud.nacos.NacosConfigManager;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -29,7 +26,6 @@ public class NacosDruidFilterConfiguration {

@Bean
@ConditionalOnProperty(value = "spring.nacos.config.proxy.druid.enabled", havingValue = "true")
@ConditionalOnBean(NacosConfigManager.class)
public NacosDruidConfigFilter nacosDruidFilter(Environment environment) {
String proxyDataId = environment.getProperty("spring.nacos.config.proxy.druid.data-id");
return new NacosDruidConfigFilter(proxyDataId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
com.alibaba.cloud.nacos.NacosConfigAutoConfiguration
com.alibaba.cloud.nacos.NacosConfigBootstrapConfiguration
com.alibaba.cloud.nacos.endpoint.NacosConfigEndpointAutoConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public class NacosConfigDataLocationResolverTest {
@BeforeEach
void setup() {
this.environment = new MockEnvironment();
environment.setProperty("spring.config.import", "nacos:test.properties");
this.environmentBinder = Binder.get(this.environment);
this.resolver = new NacosConfigDataLocationResolver(new DeferredLogs());
Mockito.when(bootstrapContext.isRegistered(ArgumentMatchers.eq(ConfigService.class))).thenReturn(true);
Expand All @@ -73,14 +72,14 @@ void setup() {
void testIsResolvable_givenIncorrectPrefix_thenReturnFalse() {
assertThat(
this.resolver.isResolvable(this.context, ConfigDataLocation.of("test:")))
.isFalse();
.isFalse();
}

@Test
void testIsResolvable_givenCorrectPrefix_thenReturnTure() {
assertThat(
this.resolver.isResolvable(this.context, ConfigDataLocation.of("nacos:")))
.isTrue();
.isTrue();
assertThat(this.resolver.isResolvable(this.context,
ConfigDataLocation.of("optional:nacos:"))).isTrue();
}
Expand All @@ -93,7 +92,7 @@ void testIsResolvable_givenDisable_thenReturnFalse() {
this.environment.setProperty(prefix + ".config.enabled", "false");
assertThat(
this.resolver.isResolvable(this.context, ConfigDataLocation.of("nacos:")))
.isFalse();
.isFalse();
}

@Test
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.alibaba.cloud.nacos.refresh.SmartConfigurationPropertiesRebinder;
import com.alibaba.cloud.nacos.refresh.condition.ConditionalOnNonDefaultBehavior;

import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.SearchStrategy;
import org.springframework.cloud.context.properties.ConfigurationPropertiesBeans;
Expand All @@ -48,7 +47,6 @@ public ConfigurationPropertiesRebinder smartConfigurationPropertiesRebinder(Conf
}

@Bean
@ConditionalOnBean(NacosConfigManager.class)
public NacosPropertySourceLocator nacosPropertySourceLocator(
NacosConfigManager nacosConfigManager) {
return new NacosPropertySourceLocator(nacosConfigManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public void testUsingSmartConfigurationPropertiesRebinder_whenBehaviorIsNotDefau
.web(WebApplicationType.NONE)
.properties("spring.cloud.nacos.config.refresh-behavior=specific_bean")
.properties("spring.cloud.nacos.server-addr=123.123.123.123:8848")
.properties("spring.cloud.nacos.config.import-check.enabled=false")
.properties("spring.config.import=nacos:test.properties").run();
.properties("spring.cloud.nacos.config.import-check.enabled=false").run();

ConfigurationPropertiesRebinder rebinder = context
.getBean(ConfigurationPropertiesRebinder.class);
Expand All @@ -65,8 +64,7 @@ public void testUsingConfigurationPropertiesRebinder_whenBehaviorIsDefault() {
context = new SpringApplicationBuilder(RebinderConfiguration.class)
.web(WebApplicationType.NONE)
.properties("spring.cloud.nacos.server-addr=123.123.123.123:8848")
.properties("spring.cloud.nacos.config.import-check.enabled=false")
.properties("spring.config.import=nacos:test.properties").run();
.properties("spring.cloud.nacos.config.import-check.enabled=false").run();

ConfigurationPropertiesRebinder rebinder = context
.getBean(ConfigurationPropertiesRebinder.class);
Expand Down
Loading