目录
报错日志:
Caused by: java.lang.IllegalStateException: Cannot load driver class: org.postgresql.Driver
at org.springframework.util.Assert.state(Assert.java:97)
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:171)
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:123)
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:48)
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:90)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
... 83 common frames omitted
解决思路:
看报错是说未加载到pg数据库的驱动,但是这个项目我使用的是mysql的数据库,所以很疑惑为什么报这个错
于是在application.yml文件中指明了driver-class-name是mysql的驱动
但是仍然是报同样的错误
问题解决:
最后是在nacos配置文件中发现同样配置了driver-class-name指明是pgdriver,(找到报错日志里为啥说是pg数据库了),直接把nacos中的driver-class-name配置改为com.mysql.cj.jdbc.Driver
总结:
nacos中的配置把本地配置覆盖掉了,所以本地配置不起作用