代码之家  ›  专栏  ›  技术社区  ›  JonD

如何解决IntelliJ IDE中的Spring Boot BD错误

  •  0
  • JonD  · 技术社区  · 2 年前

    在将Spring Boot配置为MySQL并运行应用程序时,我收到了以下错误。

    由以下原因引起:org.springframework.beans.factory.BeanCreationException:创建在类路径资源[org/springframework/boot/autoconfig/jdbc/DataSourceConfiguration$Hikari.class]中定义的名称为“dataSource”的bean时出错:未能实例化[com.zaxxer.Hikari.HikariDataSource]:工厂方法“dataSource”引发异常,消息为:无法加载驱动程序类:com.mysql.cj.jdbc.driver

    我没有使用IntelliJ IDEA Ultimate版本。我使用的是IntelliJ IDEA社区版本。我确实看到IDE在我的application.properties文件中显示了以下错误消息:

    IntelliJ IDEA Ultimate支持Spring Boot配置

    以下是我的application.properties文件L中的配置

    #configuration
    spring.jpa.hibernate.ddl-auto=update
    spring.datasource.url=jdbc:mysql://localhost:3306/JRPropertyManagement
    spring.datasource.username=xxxx
    spring.datasource.password=xxxxxxxxxx
    
    spring.datasource.driver-class-name=com.mysql.cj.jdbc.driver
    

    我可能配置不正确,或者问题可能是我没有使用IntelliJ IDEA Ultimate版本?如果这个问题与我没有使用IntelliJ IDEA Ultimate版本有关,那么Eclipse会是Spring Boot Java的更好的IDE吗?

    1 回复  |  直到 2 年前
        1
  •  1
  •   Sairam Nagaraj    2 年前

    这不是IntellIJ终极版的问题,您可以使用您选择的任何IDE。

    问题是驱动程序类名是com.mysql.cj.jdbc.driver,而不是com.mysql.cj.jdbc.driver。请注意,Spring建议不要显式指定驱动程序,因为它会自己注册

    希望这能有所帮助