H2 Database not found error: 90146. H2 database is not created on start

后端 未结 8 1678
无人及你
无人及你 2021-01-19 01:55

Just created a simple spring-boot project from the spring initializer. I went to add a local h2 db for testing and am unable to login. Seems that it cannot create the test d

相关标签:
8条回答
  • 2021-01-19 02:46

    If you are using spring boot in order to use h2 DB, make sure you have dependencies on your pom.xml file

    <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
         <groupId>com.h2database</groupId>
         <artifactId>h2</artifactId>
         <scope>runtime</scope>
    </dependency>
    

    Your application.yml makes it possible to access h2 DB by URI /h2-console preceded by server URL and to connect to DB named "testdb" with username "sa" and no password, after the application has been started on the server.

    0 讨论(0)
  • 2021-01-19 02:47

    I had the same error and I found these to be helpful:

    Adding a pre-2019 version to the pom.xml file as below:

    <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.193</version>
    </dependency>
    

    This fixes the error but isn't the right way to do it. The newer version of H2 Database do not create a new database as it doesn't exist by default and are enabled to false for security purposes.

    A better way would be adding making changes to url as:

    jdbc:h2:mem:testdb;IFEXISTS=FALSE;
    

    Hope it helps. I made changes in my application.properties file.

    0 讨论(0)
提交回复
热议问题