CloudException:找不到合适的云连接器

CloudException: No suitable cloud connector found

我的项目依赖于 spring-boot-starter-cloud-connectorsspring-cloud-localconfig-connector。这是我的代码:

@Configuration
class MyConfig {

    @Bean
    public CloudFactory cloudFactory() {
        CloudFactory cf = new CloudFactory();
        cf.registerCloudConnector(new LocalConfigConnector());
        return cf;
    }

}

@Component
class MyComponent {

    @Autowired
    CloudFactory cf;

    @EventListener(value = ApplicationStartedEvent.class)
    public void postConstruct() {
        Cloud cloud = cf.getCloud();
    }

}

当我尝试在本地 运行 上面的代码时,出现异常:

org.springframework.cloud.CloudException: No suitable cloud connector found

尽管 parent 的版本无关紧要,但我正在使用 2.1.8.RELEASE

有人能指出上面的代码有什么问题吗?

您必须添加默认数据源:

mysql://user:password@localhost:3306/databasename

您可以使用 运行 配置来设置它,或者为它创建一个单独的 properties 文件。