带h2数据库的spring引导,无法连接

3hvapo4f  于 2021-07-26  发布在  Java
关注(0)|答案(2)|浏览(350)

我是一个新的Sping Boot 。我尝试在spring启动项目中使用h2数据库,但是当我输入 http://localhost:8080/h2-console/ ,仅显示页面

{
    "username": "Invalid Username",
    "password": "Invalid Password"
}

我不知道为什么,怎么解决。

c0vxltue

c0vxltue1#

要使用h2控制台,您需要在.properties文件中配置它

spring.h2.console.enabled=true
spring.h2.console.path=/h2console/

哪里 /h2console/ 是您要在浏览器上使用的路径,以便您可以将其更改为任何内容。

vybvopom

vybvopom2#

要使用h2,必须在application.properties文件中设置用户名和密码:


# h2

spring.datasource.username=sa
spring.datasource.password=

默认情况下,不设置h2的密码。因此密码为空。
以下是有关spring boot和h2数据库的更多信息的有用链接:
https://www.baeldung.com/spring-boot-h2-database

相关问题