gpt4 book ai didi

java - 无法加载驱动程序类 : com. mysql.jdbc.Driver Spring

转载 作者:IT老高 更新时间:2023-10-28 13:47:11 24 4
gpt4 key购买 nike

spring.freemarker.cache:false


spring.datasource.url=jdbc:mysql://localhost/mydb
spring.datasource.username=user
spring.datasource.password=pass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

即使定义了驱动程序类名,我也会收到此错误

java.lang.IllegalStateException: Cannot load driver class: com.mysql.jdbc.Driver at org.springframework.util.Assert.state(Assert.java:392) ~[spring-core-4.2.1.RELEASE.jar:4.2.1.RELEASE] at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.getDriverClassName(DataSourceProperties.java:153) ~[spring-boot-autoconfigure-1.3.0.M5.jar:1.3.0.M5] at org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration$NonEmbeddedConfiguration.dataSource(DataSourceAutoConfiguration.java:119) ~[spring-boot-autoconfigure-1.3.0.M5.jar:1.3.0.M5] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_60] at ......

然后继续

最佳答案

如果您使用的是 Maven,请将其添加到您的 pom.xml :

(推荐)对于MySQL 5.6, 5.7, 8.xJava >= 8使用;

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
</dependency>

(旧版)对于 MySQL <= 5.5Java <= 7JDBC < 4.2使用;

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version>
</dependency>

More details on Connector/J versions

关于java - 无法加载驱动程序类 : com. mysql.jdbc.Driver Spring,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33123985/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com