我正在使用 WebFlux 堆栈中的 h2 db 以及 Netflix DGS 构建一个新的 Spring boot 应用程序。我想访问 h2 DB 控制台。我已使用以下配置,但无法使用此配置访问我的 H2 DB 控制台。尽管数据库正在旋转并且在应用程序启动期间我可以以编程方式将数据加载到数据库中。
gradle file
------------
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation(platform("com.netflix.graphql.dgs:graphql-dgs-platform-dependencies:5.5.5"))
implementation 'com.netflix.graphql.dgs:graphql-dgs-webflux-starter:5.5.5'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'com.h2database:h2'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
}
application.yml
---------------
spring:
config:
activate:
on-profile: local
graphql:
graphiql:
#http://localhost:8080/graphiql
enabled: true
datasource:
url: jdbc:h2:mem:testdb;MODE=PostgreSQL
driverClassName: org.h2.Driver
username: sa
password: password
h2:
console:
enabled: true
path: /h2-console
如果我尝试访问 H2 控制台 url 收到 404 错误。
这是我的网址 - http://localhost:8080/h2-console/
H2ConsoleAutoConfiguration
不适用于 Spring webflux。您可能需要通过为 H2 控制台定义服务器来手动配置 H2 配置。您可以在代码中创建一个网络服务器,然后尝试使用它。