alibaba / spring-cloud-alibaba

Spring Cloud Alibaba provides a one-stop solution for application development for the distributed solutions of Alibaba middleware.
https://sca.aliyun.com
Apache License 2.0
27.94k stars 8.33k forks source link

Can't read config from spring, when without ".yml" #3810

Closed Sorieee closed 1 month ago

Sorieee commented 3 months ago

Which Component Nacos Config Describe the bug When I config like this, code can't read config from spring.

  config:
    import:
      - nacos:${spring.application.name}?refreshEnabled=true&group=DEFAULT_GROUP

NacosConfigDataLoader can pull config from server image But image When I config

config:
    import:
      - nacos:${spring.application.name}.yml?refreshEnabled=true&group=DEFAULT_GROUP

Can read config image ConfigPrinter

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class ConfigPrinter implements CommandLineRunner {

    @Value("${spring.datasource.url:}")
    private String datasourceUrl;

    @Value("${spring.datasource.username:}")
    private String datasourceUsername;

    @Value("${spring.datasource.password:}")
    private String datasourcePassword;

    @Override
    public void run(String... args) throws Exception {
        System.out.println("Datasource URL: " + datasourceUrl);
        System.out.println("Datasource Username: " + datasourceUsername);
        System.out.println("Datasource Password: " + datasourcePassword);
    }
}

Additional context JDK21

<spring-boot.version>3.2.0</spring-boot.version>
<spring-cloud-alibaba.version>2023.0.1.0</spring-cloud-alibaba.version>
<spring-cloud.version>2023.0.3</spring-cloud.version>
github-actions[bot] commented 2 months ago

This issue has been open 30 days with no activity. This will be closed in 7 days.

github-actions[bot] commented 1 month ago

This issue has been automatically marked as stale because it hasn't had any recent activity.If you think this should still be open, or the problem still persists, just pop a reply in the comments and one of the maintainers will (try!) to follow up. Thank you for your interest and contribution to the Sping Cloud Alibaba Community.