Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nacos property arg bug #232

Merged
merged 1 commit into from
Mar 7, 2022
Merged

Conversation

shouyuwang
Copy link
Contributor

When I have configurations with the same name in different yaml files,the result obtained through @NacosConfigurationProperties may be a bug.

@shouyuwang
Copy link
Contributor Author

FindBug Test

Test1Config

@Configuration
@NacosConfigurationProperties(groupId = "test1", dataId = "test1.yaml", autoRefreshed = true)
public class Test1Config {

    /**
     *  test
     */
    private String test;


    public String getTest() {
        return test;
    }

    public void setTest(String test) {
        this.test = test;
    }
}

Test2Config

@Configuration
@NacosConfigurationProperties(groupId = "test2", dataId = "test2.yaml", autoRefreshed = true)
public class Test2Config {

    /**
     * test
     */
    private String test;


    public String getTest() {
        return test;
    }

    public void setTest(String test) {
        this.test = test;
    }
}

TestsClass

@EnableScheduling
@SpringBootApplication
public class NacosTestApplication {

    public static void main(String[] args) {
        SpringApplication.run(NacosTestApplication.class, args);
    }

    private Logger logger = LoggerFactory.getLogger(NacosTestApplication.class);

    @Autowired
    private Test1Config test1Config;

    @Autowired
    private Test2Config test2Config;

    @Scheduled(cron = "0/5 * * * * ?")
    public void print(){
        logger.info("test1:{}, test2:{}", test1Config.getTest(), test2Config.getTest());
    }
}

Nacos test1.yaml

test-config

Nacos test2.yaml

teest2-config

Test RunResult

run-result

test1.yaml update

test1-update

test1 change result

test1-update-result

test2.yaml update

test2update

test2 change result

test2update-result

FixBug Test

NacosPropertySourceConstruction Mthod is

public NacosPropertySource(String dataId, String groupId, String name,
			String nacosConfig, String type) {
  super(name, toProperties(dataId, groupId, nacosConfig, type));
  this.type = type;
}

But in NacosBootConfigurationPropertiesBinder doBindmethod useNacosPropertySource propertySource = new NacosPropertySource(name, dataId, groupId, content, configType);Maybe the name is not a right order.environment.getPropertySources().remove(name) environment can not remove the name. So I change to NacosPropertySource propertySource = new NacosPropertySource(dataId, groupId, name, content, configType);

Test Result

fix-result

test2.yaml update

test2-rollback

test2 change result

test2-rollback-result

test1.yaml update

test1-rollback

test1 change result

test1-rollback-result

@shouyuwang shouyuwang changed the title fix nacos property arg bug fix: nacos property arg bug Mar 4, 2022
@shouyuwang
Copy link
Contributor Author

@xuechaos please take a look, if you have time,thanks.

@chuntaojun chuntaojun merged commit 147829a into nacos-group:master Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants