5

I am building a brand new application with Grails 4 and I am trying to look at my database as I make changes to the application, but I am not able to access the h2 database with the usual URL http://localhost:8080/dbconsole.

I have looked at the documentation and under "4.4.4 Database Console" it says that I should be able to access it using the above URL. It also says that it is enabled by default, which leads me to more confusion.

I have not changed anything in my application.yml after creating the app and I have only created one domain class and that is the only thing I have changed. I have also tried changing the serverURL as mentioned in 4.4.4 in the documentation, but I have changed that back to the default.

Here is my datasource and dev environment from application.yml

dataSource:
    pooled: true
    jmxExport: true
    driverClassName: org.h2.Driver
    username: sa
    password: ''

environments:
    development:
        dataSource:
            dbCreate: create-drop
            url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
Drummerman921
  • 311
  • 3
  • 16

1 Answers1

7

I found an answer here.

According to the site, the integration has been removed since Spring Boot already includes h2, but the url is now /h2-console.

If you have removed Spring Boot's Developer Tools developmentOnly("org.springframework.boot:spring-boot-devtools") from the dependencies in the build.gradle, then you will also have to add the following to the application.yml(There should already be a spring section that you can add this to by default).

spring:
  h2:
    console:
      enabled: true

After restarting the app you should be able to navigate to http://localhost:8080/h2-console and it will show the normal h2 db login screen.

Drummerman921
  • 311
  • 3
  • 16
  • "You will also have to add the following to the application.yml" - Are you sure that you have to set `spring.h2.console.enabled` to true? I think it works by default without that. – Jeff Scott Brown Aug 20 '19 at 18:40
  • I tried running the application without `spring.h2.console.enabled` set in `application.yml` and I ran into the same problem (404 not found). – Drummerman921 Aug 21 '19 at 16:13
  • I just found out that if you are using Spring Boot's Developer Tools, then you will not have to add anything to `application.yml`. I had to add that since I needed to remove the developer tools from the dependencies. I have changed my answer to include this information. – Drummerman921 Aug 21 '19 at 16:17