先看配置文件:
问题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.youkuaiyun.com/u013100581/article/details/92759519
解决:修改client配置文件命名
问题5:@Runwith,@SpringRun,@SpringbootTest爆红,依赖不到
原因:common模块主要是其他各模块都几乎要用到的Jar,我将spring-boot-starter-test的依赖也放到这里了,问题就出现在这里,因为引入时,指定的scope范围是test,在某一模块,引入common包时,并不能成功引入测试依赖。
解决:测试单独依赖。