Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the port of the spring boot h2 console

I am trying to view the spring boot h2 console. However, the default port is 8080, and that port is already being used on my machine.

Is there a way for me to change the web port that spring boot uses for h2? There's a lot of documentation around changing the path, but I can't find anything about changing the port. This is my current config set up:

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

EDIT As mentioned by Atul K below, the h2 web console is available on the configured server.port. However, this isn't an option for me as our spring boot application performs mandatory header validation for all requests coming to the spring boot app. Is it possible to independently configure a port for the h2 web console and the spring boot app?

like image 509
Ben Green Avatar asked Oct 31 '25 06:10

Ben Green


2 Answers

Add server.port=8081 to your config. As its embedded, should use the same port of that of service. So should be able to access it using url: http://localhost:8081/h2-console

like image 178
Atul Kulkarni Avatar answered Nov 01 '25 18:11

Atul Kulkarni


For instance, you app yml config:

#tomcat
server.port: 7999

#h2
spring:
  h2:
    console.enabled: true

Start app and h2-console is available on 7999 port enter image description here

like image 38
AlexPes Avatar answered Nov 01 '25 20:11

AlexPes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!