我正在做一个Spring项目。我遇到了一个问题;我无法连接到mysql驱动程序。这是pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
这是申请表。属性代码:
spring.datasource.url=jdbc:mysql://localhost:3306/stock_produit
spring.datasource.username=root
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=create
spring.datasource.driver-class-name=com.mysql.cj.jdbc
Logcat:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-02-12 01:40:47.353 ERROR 10086 --- [ main] o.s.boot.SpringApplication : Application run failed.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc
...
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc
....
Caused by: java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc
at org.springframework.util.Assert.state(Assert.java:94) ~[spring-core-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:224) ~[spring-boot-autoconfigure-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:176) ~[spring-boot-autoconfigure-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:43) ~[spring-boot-autoconfigure-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:83) ~[spring-boot-autoconfigure-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
... 43 common frames omitted
感谢您的帮助。
如果使用MySQL server 8和连接器j8.0,则使用这个类名-com.mysql.cj.jdbc.驱动程序
在application.properties
中,您定义的驱动程序类名在Spring数据依赖项中找不到。所以,
我觉得你应该试试这个。。
spring.datasource.url=jdbc:mysql://localhost:3306/stock_produit
spring.datasource.driverClassName=com.mysql.jdbc.Driver
而不是
spring.datasource.url=jdbc:mysql://localhost:3306/stock_produit
spring.datasource.driver-class-name=com.mysql.cj.jdbc
注意:您正在尝试连接mysql数据库,这需要com.mysql。jdbc。驱动程序,它在spring boot data中可用。
希望这能帮到你。。
这是hibernate.cfg.xml: 这是Hibernate实用程序文件:
我正在处理Spring Boot项目,突然遇到应用程序无法加载MySQL jdbc的问题。(我编译了一次这个项目,没有改变任何东西) 这是我的pom.xml: 这是我的application.properties: Logcat: MySQL数据库最初是使用hibernate创建的。这些配置工作正常,但我不确定这里的真正问题是什么 编辑:我删除了。m2文件夹并从一开始安装所有依赖项。
嘿,伙计们,还有一个问题,下面是信息
我有一个简单的Spring Boot应用程序(通过Spring Roo生成)。 数据库配置如下:
我正在运行以下代码,但是我得到了关于Oracle类名称的错误。我已经用oracle jar文件设置了classpath环境变量,但它不起作用。有人能帮我吗?我不知道还能做什么。我真的很感谢你的帮助 这就是错误:由:java引起。sql。SQLException:无法加载JDBC驱动程序类“oracle”。jdbc。驾驶员OracleDriver's
即使驱动程序类名已定义,我也会收到此错误 Java语言lang.IllegalStateException:无法加载驱动程序类:com。mysql。jdbc。组织的驱动程序。springframework。util。明确肯定state(Assert.java:392)~[spring-core-4.2.1.RELEASE.jar:4.2.1.RELEASE]位于org。springframewor