'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?
Solution 1:[1]
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
Solution 2:[2]
For instance, you app yml config:
#tomcat
server.port: 7999
#h2
spring:
h2:
console.enabled: true
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Atul Kulkarni |
| Solution 2 | AlexPes |

