当我试图和spring共进午餐时,我犯了这个错误?

dbf7pr2w  于 2021-07-14  发布在  Java
关注(0)|答案(2)|浏览(306)

我正在用mysql编写一个spring启动初始化器示例。
当我启动我的应用程序,我得到下面的错误。
对这个问题有什么建议吗?


***************************

APPLICATION FAILED TO START

***************************

Description:

Failed to configure a DataSource: no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class

Action:

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).

我试过了!!!!

server.port=8081
spring.datasource.url=jdbc://localhost:3306/tp
spring.datasource.username=root
spring.datasource.password=
spring.jpa.show-sql= true
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.hibernate.enable_lazy_load_no_trans=true
klsxnrf1

klsxnrf11#

尝试使用

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database-platform = org.hibernate.dialect.MySQL5Dialect

或者其他方言版本

42fyovps

42fyovps2#

要使用mysql开发spring/boot应用程序,请执行以下步骤

Remove H2 Dependency From pom.xml 
<!--
<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>test</scope>
</dependency>
-->

Add a Dependency for MYSQL Database Connector to pom.xml
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

在本地系统或任何远程位置设置mysql数据库。

Configure application.properties to connect to your database.
spring.jpa.hibernate.ddl-auto=none
spring.datasource.url=jdbc:mysql://localhost:3306/<DBNAME>
spring.datasource.username=<USERNAME>
spring.datasource.password=<PASSWORD>

请按照步骤操作,并告知我们任何问题

相关问题