我正在使用Spring Boot JPA创建应用程序,正在将MySQL用作数据库.
I am creating an application using Spring Boot JPA, I am using MySQL as a database.
以下是我的application.properties
Following is my application.properties
spring.jpa.hibernate.ddl-auto=update spring.datasource.url=jdbc:mysql://localhost:3306/mydb spring.datasource.username=root spring.datasource.password= spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect我添加了以下依赖项
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.17</version> </dependency>当我检查调试日志时,我可以在类路径中看到mysql java连接器,但仍然出现以下错误
When I checked in debug logs I can see mysql java connector in my classpath but still I am getting following errors
2019-07-29 10:03:00.742信息10356 --- [主] o.a.c.c.C. [Tomcat].[localhost].[/]:初始化Spring 嵌入式WebApplicationContext 2019-07-29 10:03:00.742信息10356- [main] o.s.web.context.ContextLoader:根 WebApplicationContext:初始化在1534毫秒内完成2019-07-29 10:03:00.789 WARN 10356 --- [main] ConfigServletWebServerApplicationContext:遇到异常 在上下文初始化期间-取消刷新尝试: org.springframework.beans.factory.UnsatisfiedDependencyException: 使用名称创建bean时出错 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': 通过构造函数参数0表示的不满足的依赖关系; 嵌套的例外是 org.springframework.beans.factory.BeanCreationException:错误 创建在类路径资源中定义的名称为"dataSource"的bean [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration $ Hikari.class]: 通过工厂方法实例化Bean失败;嵌套的例外是 org.springframework.beans.BeanInstantiationException:失败 实例化[com.zaxxer.hikari.HikariDataSource]:工厂方法 'dataSource'引发异常;嵌套的例外是 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties $ DataSourceBeanCreationException: 无法确定合适的驱动程序类别2019-07-29 10:03:00.789 INFO 10356 --- [main] o.apache.catalina.core.StandardService:正在停止服务[Tomcat] 2019-07-29 10:03:00.805 INFO 10356 --- [主要] ConditionEvaluationReportLoggingListener:
2019-07-29 10:03:00.742 INFO 10356 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2019-07-29 10:03:00.742 INFO 10356 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1534 ms 2019-07-29 10:03:00.789 WARN 10356 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: 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 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class 2019-07-29 10:03:00.789 INFO 10356 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2019-07-29 10:03:00.805 INFO 10356 --- [ main] ConditionEvaluationReportLoggingListener :
启动ApplicationContext时出错.显示条件报告 在启用调试"的情况下重新运行您的应用程序. 2019-07-29 10:03:00.805 错误10356 --- [main] o.s.b.d.LoggingFailureAnalysisReporter:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2019-07-29 10:03:00.805 ERROR 10356 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
********************************应用程序无法启动
*************************** APPLICATION FAILED TO START
说明:
无法配置数据源:未指定'url'属性,并且 无法配置任何嵌入式数据源.
Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.
原因:无法确定合适的驱动程序类别
Reason: Failed to determine a suitable driver class
动作:
请考虑以下事项:如果要嵌入式数据库(H2,HSQL或 Derby),请将其放在类路径上.如果您有数据库设置 要从特定配置文件加载您可能需要激活它(否 个人资料当前处于活动状态).
Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
推荐答案
我的配置中有一个错误,我无法检测到,重新创建了相同的项目,一切开始正常工作
It was some mistake in my configuration which I couldn't detect, I re-created same project and things started working
更多推荐
Spring Boot JPA MySQL:无法确定合适的驱动程序类
发布评论