配置application.properties后访问H2控制台仍出现白标错误页
解决H2控制台访问白标错误的问题
你的配置里存在几处拼写和层级错误,导致H2控制台的配置未被正确加载:
- 配置前缀大小写错误:原配置的
Spring:首字母大写,Spring Boot配置对大小写敏感,必须改为小写spring:,否则配置不会生效。 - 配置项拼写错误:
onsole.settings.trace缺少字母c,正确应为console.settings.tracescpring.h2.console.settings.web-allow-others里的scpring是拼写错误,应为spring
- 配置层级错误:
web-allow-others属于h2.console.settings的子项,不能单独作为顶级配置存在
修正后的完整配置如下:
server: port: 8080 spring: h2: console: enabled: true path: /h2-console settings: trace: false web-allow-others: false datasource: url: jdbc:h2:mem:testdb username: sa password: driverClassName: org.h2.Driver jpa: show-sql: true defer-datasource-initialization: true database-platform: org.hibernate.dialect.H2Dialect
修正后重启应用,访问http://localhost:8080/h2-console即可正常打开H2控制台。另外请确保项目已正确引入H2数据库依赖。
内容的提问来源于stack exchange,提问作者Hugo
相关产品推荐
相关产品推荐

