使用Spring Cloud Config 遇到的坑

server端

按照教程做,没有遇到问题。

client端

  • demo里面不能写localhost,必须改成ip。
  • 配置要放到bootstrap.yml里面。优先于application加载才不会报错

ConfigClient datasource url 无法获取

一启动就报datasource url

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
 
Reason: Failed to determine a suitable driver class
  • Spring Cloud 进阶之路 – 统一配置中心 Config Client 端配置

其实加不加eureka都没有关系。

  • 在demo项目中测试,可以获取到spring.datasource.url属性地址。
  • 这里我们把自动装配改成手动装配
    1. @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
    2. 手动配置
    	// 将这个对象放入Spring容器中
    @Bean
    // 表示这个数据源是默认数据源
    @Primary
    // 读取application.properties中的配置参数映射成为一个对象
    // prefix表示参数的前缀
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource getDateSource1() {
    	return DataSourceBuilder.create().build();
    }
    
  • 不行这样一配置就出现Error creating bean with name 'appRepositoryServiceBean' defined in class path resource org/flowable/spring/boot/app/AppEngineServicesAutoConfiguration 错误,这个问题的原因是flowable自动装配的时候需要datasource,但是在这里还没有初始化datasource,所以报错。不可能一个一个的改成手动装配。
  • 先加在本地的配置文件里面吧,以后再说。

和eureka整合。

  • 我是想把config-service的地址隐藏掉,这样普通人就不知道配置文件内容了。
  • 但是一整合就报
Could not locate PropertySource: I/O error on GET request for "http://iZ2zeaam6qj4v045dafpj5Z:8762/gather-bus/dev/master": iZ2zeaam6qj4v045dafpj5Z; nested exception is java.net.UnknownHostException: iZ2zeaam6qj4v045dafpj5Z
  • 这里iZ2zeaam6qj4v045dafpj5Z找不到??他的真实是什么??
  • 去设置注册中心真实ip一看是阿里云内网。里面有解决办法

参考资料

  • 史上最简单的SpringCloud教程 | 第七篇: 高可用的分布式配置中心(Spring Cloud Config)(Finchley版本)
  • 史上最简单的SpringCloud教程 | 第六篇: 分布式配置中心(Spring Cloud Config)(Finchley版本)
  • Spring Cloud Config配置详解

Spring Cloud Bus自动所有项目刷新

  • Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded 的三种解决办法
  • springboot-mybatis多数据源的两种整合方法

你可能感兴趣的:(架构,#,力盟亚任职,#,spring家族)