SpringBootの異常——Cannot determine embedded database driver class for database type NONE

問題:mysql

啓動SpringBoot報錯:spring

org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException:sql

Cannot determine embedded database driver class for database type NONE.數據庫

If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active)springboot

解決一:修改pom.xml 的數據庫配置。h2數據庫會將數據臨時保存在內存中,可是不會持久化。app

<dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
</dependency>url

解決二:添加數據庫鏈接配置。SpringBoot啓動後會加載classpath(即src路徑)下的application.properties文件。spa

spring.datasource.url=jdbc:mysql://192.168.x.xx:3306/lzs
spring.datasource.username=root
spring.datasource.password=admin
spring.datasource.driver-class-name=com.mysql.jdbc.Driverxml

Ps:我使用的是mysql數據庫內存

分析:痛則不通,通則不痛。問題的緣由是springboot啓動會鏈接數據庫,而「新手」不太肯定在哪裏配置。

SpringBoot啓動後會加載classpath(即src路徑)下的application.properties文件。

數據庫配置是:

spring.datasource.url=jdbc:mysql://192.168.x.xx:xxxx/xxx
spring.datasource.username=root
spring.datasource.password=admin
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

#192.168.x.xx:xxxx/xxx其中x.xx是你本地的IP,xxxx是數據庫端口,xxx是鏈接的數據庫。

相關文章
相關標籤/搜索