如何更改spring boot h2控制台的端口

Ben*_*een 3 java h2 spring-boot

我正在尝试查看 spring boot h2 控制台。但是,默认端口是 8080,并且该端口已在我的机器上使用。

有没有办法让我更改 spring boot 用于 h2 的 Web 端口?有很多关于更改路径的文档,但我找不到任何关于更改端口的信息。这是我当前的配置设置:

spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
spring.h2.console.settings.web-allow-others=true
spring.jpa.database=h2
Run Code Online (Sandbox Code Playgroud)

编辑 正如下面 Atul K 所提到的,h2 Web 控制台在配置的server.port. 但是,这对我来说不是一个选项,因为我们的 Spring Boot 应用程序对进入 Spring Boot 应用程序的所有请求执行强制性标头验证。是否可以为 h2 web 控制台和 spring boot 应用程序独立配置端口?

Atu*_*l K 7

添加server.port=8081到您的配置中。作为其嵌入式,应使用与服务相同的端口。所以应该能够使用 url 访问它:http://localhost:8081/h2-console