title: H2 memory database not starting
body: <p>I have a spring boot application deployed on heroku, which uses a postgres db hosted on heroku.</p>
  <p>I have configured config vars on heroku and am using them in my spring boot application like this :
  <a href="https://i.stack.imgur.com/RmGkXm.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RmGkXm.png" alt="enter image description here" /></a></p>
  <p>and in my code I use a connectionService:</p>
  <pre><code> public static Connection getConnection() {
          try {
              final String dbUrl = System.getenv(&quot;SPRING_DATASOURCE_URL&quot;);
              final String dbUserName = System.getenv(&quot;SPRING_DATASOURCE_USERNAME&quot;);
              final String dbPassword = System.getenv(&quot;SPRING_DATASOURCE_PASSWORD&quot;);
              return DriverManager.getConnection(dbUrl,dbUserName,dbPassword);
          } catch(final SQLException e) {
              LoggerService.writeErrorMsg(&quot;There was an error with the connection : [errorMsg: \n&quot; + e + &quot; ]&quot;);
          }
          return null;
      }
  }
  </code></pre>
  <p>And I use DAOs with CRUD methods to access the database, for example :</p>
  <pre><code>    public static AdminAccount getAdminAccountById(final int id) throws SQLException {
      final Connection connection = ConnectionService.getConnection();
      final String sql = &quot;select * from admin_account where id = ?&quot;;
      final PreparedStatement preparedStatement = connection.prepareStatement(sql);
      preparedStatement.setInt(1, id);
      final ResultSet resultSet = preparedStatement.executeQuery();
  
        if (resultSet.next()) {
          final AdminAccount adminAccount = new AdminAccount();
          adminAccount.setId(resultSet.getInt(&quot;id&quot;));
          adminAccount.setFacility(resultSet.getString(&quot;facility&quot;));
          adminAccount.setFirstName(resultSet.getString(&quot;first_name&quot;));
          adminAccount.setLastName(resultSet.getString(&quot;last_name&quot;));
          adminAccount.setEmail(resultSet.getString(&quot;email&quot;));
          connection.close();
          return adminAccount;
        } else {
          return null;
        }
    }
  </code></pre>
  <p>This is working fine on the deployed app, however it no longer works in localhost since I removed the hardcoded db credentials. Also, after reading about best practices, I have figured out that it's best to have a separate DB only for testing/development, so you don't actually run queries against the production DB.</p>
  <p>I have tried setting up a h2 memory database but with no luck. It doesn't seem to even start when I check the logs.</p>
  <p>This is my pom.xml :</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.6.3&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;...&lt;/groupId&gt;
      &lt;artifactId&gt;...&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;rbooking&lt;/name&gt;
      &lt;description&gt;...&lt;/description&gt;
      &lt;properties&gt;
          &lt;java.version&gt;17&lt;/java.version&gt;
      &lt;/properties&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
                  &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
                  &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-jdbc&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-security&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
              &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
              &lt;version&gt;42.3.6&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.h2database&lt;/groupId&gt;
              &lt;artifactId&gt;h2&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
  
          &lt;!-- Switch back from Spring Boot 2.x standard HikariCP to Tomcat JDBC,
          configured later in Heroku (see https://stackoverflow.com/a/49970142/4964553) --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.tomcat&lt;/groupId&gt;
              &lt;artifactId&gt;tomcat-jdbc&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-configuration-processor&lt;/artifactId&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
              &lt;artifactId&gt;lombok&lt;/artifactId&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;resources&gt;
              &lt;resource&gt;
                  &lt;directory&gt;src/main/resources&lt;/directory&gt;
                  &lt;excludes&gt;
                      &lt;exclude&gt;app/**&lt;/exclude&gt;
                  &lt;/excludes&gt;
              &lt;/resource&gt;
          &lt;/resources&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;com.heroku.sdk&lt;/groupId&gt;
                  &lt;artifactId&gt;heroku-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.0.8&lt;/version&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;8&lt;/source&gt;
                      &lt;target&gt;8&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>
  <p>And this is my application.properties:</p>
  <pre><code>#PORT
  server.port = 8081
  
  #LOGGING
  logging.file.name=src/main/resources/logs/application.log
  logging.file.path=src/main/resources/logs
  logging.level.root = INFO
  
  #SECURITY
  security.basic.enable= false
  security.ignored=/**
  
  #DB
  spring.h2.console.enabled=true
  spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1
  spring.datasource.driverClassName=org.h2.Driver
  spring.datasource.username=sa
  spring.datasource.password=
  spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
  spring.jpa.generate-ddl=true
  spring.jpa.hibernate.ddl-auto=create
  spring.jpa.show-sql=true
  spring.jpa.defer-datasource-initialization=true
  spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
  spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
  
  #DEVTOOLS
  </code></pre>
  <p>When I try to access the h2 database at localhost:8081/h2-console, I get this error msg:</p>
  <p><a href="https://i.stack.imgur.com/ZOx8B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZOx8B.png" alt="enter image description here" /></a></p>
  <p>What am I missing here to make it start and recognize my application.properties variables?
  I have used the exact same application.properties configuration for another project and the h2 database starts and runs without issues</p>
  <p><strong>EDIT</strong>
  I was able to make it work by specifying an older version of the h2 maven dependency :</p>
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;com.h2database&lt;/groupId&gt;
          &lt;artifactId&gt;h2&lt;/artifactId&gt;
          &lt;version&gt;1.4.193&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>