出现了三个问题:
1.yaml文件的格式问题,首先是中文注释在某些服务器设置的字节不同时的问题,删除中文注释!!! yaml文件的格式需注意换行和语法格式有误
2.错误 java.sql.SQLNonTransientConnectionException: CLIENT_PLUGIN_AUTH is required
这个是由于部署环境mysql版本太低造成的, 由于使用的是springboot默认的 mysql-connector-java 版本是八点多需将数据库连接版本降低成5.1.37 即可
3.出现错误Could not get JDBC Connection; nested exception is java.sql.SQLException:com.mysql.cj.jdbc.Drive 这里将将数据库连接版本降低成5.1.37后,
#<!-- Mysql驱动包 --> # <dependency> # <groupId>mysql</groupId> # <artifactId>mysql-connector-java</artifactId> # <version>8.0.13</version> # </dependency> driverClassName: com.mysql.cj.jdbc.Driver #<!-- Mysql驱动包 --> # <dependency> # <groupId>mysql</groupId> # <artifactId>mysql-connector-java</artifactId> # <version>5.1.37</version> # </dependency> #driverClassName: com.mysql.jdbc.Driver
第一个问题>
控制台报错信息:
01:25:43.686 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
java.lang.IllegalStateException: Failed to load property source from location 'classpath:/application.yml'
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:549)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadForFileExtension(ConfigFileApplicationListener.java:500)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:468)
at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$null$6(ConfigFileApplicationListener.java:450)
at java.lang.Iterable.forEach(Iterable.java:75)
可以看出提示application.yml有问题。
场景一:yml的语法格式有误
application.yml:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8
datasource:
type: com.alibaba.druid.pool.DruidDataSource
解决方法:修改后的application.yml:
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
username: root
password: 123456
url: jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8
type: com.alibaba.druid.pool.DruidDataSource
ps:校验yml语法
注:注意缩进
控制台并无异常,成功运行。
场景二:application.yml文件格式问题
application.yml 配置文件内容:
spring:
datasource:
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8
username: root
password: 123456
servlet:
multipart:
max-file-size: 5MB # 限制文件上传的大小
从配置文件中可以看出语法并无问题。
解决办法:
1、File-->Settings-->File Encodings
这三个地方设置成UTF-8格式。重启启动项目。
2、如第一步并未解决问题,则可以用第二步(终极杀招)。
删除application.yml文件中所有中文注释。
第二个问题>
一. 由于使用的是springboot默认的 mysql-connector-java 版本是八点多, 导致报了这个错误
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
二. 解决办法:
将数据库连接版本降低成5.1.37 即可
部署之前打包成war包部署即可