SpringCloud-Config 搭建配置中心时遇到的坑

先看配置文件:

问题1:config client启动Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

解决:1、检查datasource的一些相关配置信息是否正确

           2、一般在配置中心有配置,没问题,客户端不想用或用不到可以启动类添加

              @SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})


问题2:config client启动报错(无限刷):The server time zone value ‘й׼ʱ’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.

原因:时区错误(jdbc 6.0以上都有这个问题)

解决:在url的字符串中添加 servertime=UTC

String url="jdbc:mysql://localhost:3306/school?useUnicode=true&characterEncoding=utf8&useSSL=true&serverTimezone=UTC";


useUnicode=true  表示使用Unicode字符,因此可以使用中文
characterEncoding=utf8  设置编码方式
useSSL=true   设置安全连接
serverTimezone=UTC    设置全球标准时间


问题3:配置中心无法访问

原因:保证容器文件访问的安全性,即保证所有的网络资源请求都需要登录,通过springboot配置属性之security,配置security.user.name和security.user.password可以初步达到安全访问的效果,所以要添加security依赖。

解决:

安全设置见:https://www.cnblogs.com/heqiyoujing/p/9441914.html


问题4:config client无法加载配置中心配置文件信息

报错:pplicationContextException: Unable to start web serve;

WebServerException: Unable to start embedded Tomcat;

BeanCreationException: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource;

UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource;

SQLException: url not set;等等异常

原因:Spring cloud client在配置的时候,配置文件要用 bootstrap.properties(yml)

具体原因:https://blog.csdn.net/u013100581/article/details/92759519

解决:修改client配置文件命名


问题5:@Runwith,@SpringRun,@SpringbootTest爆红,依赖不到

原因:common模块主要是其他各模块都几乎要用到的Jar,我将spring-boot-starter-test的依赖也放到这里了,问题就出现在这里,因为引入时,指定的scope范围是test,在某一模块,引入common包时,并不能成功引入测试依赖。

解决:测试单独依赖。

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值