<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
I got the exact same error and this was the issue in my case.
In Spring Boot 2.3.0 the property spring.datasource.generate-unique-name is set to true. This enables the random generation of the schema name.
By setting it to false the database is generated as in previous versions (jdbc:h2:mem:testdb). I find this way preferable, without the need to specify the URL manually.
Create a file with a .mv.db extension in your project's folder. Make sure that the file's name ends with .mv.db otherwise H2 console does not recognize the file (I know it doesn't make sense and I have no explanation why :D). After creating the file, enter jdbc:h2:./devdb to h2 console's JDBC URL like this:
Then you should be OK!
Step 1. Download h2 database engine from here:
https://www.h2database.com/html/main.html
Step 2. In application.properties:
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb
Step 3. Start your Spring Boot App and open:
http://localhost:8080/h2-console/
It must be working fine for you.
Use h2 dependency with the old version (1.4.192).
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.192</version>
<scope>runtime</scope>
</dependency>
Since 2.3.0, default value of generate-unique-name is true.
You can revert to the previous behavior by following setting:
spring.datasource.generate-unique-name=false
see also: https://stackoverflow.com/a/62750194/4506703
Even I came across the same set of errors when started learning data persistence with h2 database. The solution is in the console log itself. The database name is auto-generated by and can be found in the spring logs. The reason behind the error is after from 2.3.0 version release onwards if the URL is not mentioned its auto-generated.
Here is the log message which includes database URL:
INFO 16096 --- [ restartedMain] o.s.b.a.h2.H2ConsoleAutoConfiguration : H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:f1dfeade-60dd-4809-8978-42547353b2f3'
spring.datasource.generate-unique-name=false
I had also missed adding the following dependencies to pom.xml:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
In case this helps anybody. My issue was because I have this in my application.properties
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
Not sure why I added this config before. But once this is taken out, it solves my issue
Adding Spring-boot started JDBC solved my issue.
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc/2.5.2
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>2.5.2</version>
</dependency>
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
now you can use sa for username and password for password
PS : that's usually the by default configuration that spring boot uses
It's error of H2-Database:
Solution -
Let's suppose ~/Test-H-2/Project-X/DB-files path of your project (Database files)
create myTest.mv.db file in ~/Test-H-2/Project-X/DB-files folder
Add jdbc:h2:~/Test-H-2/Project-X/DB-files/myTest to JDBC URL in H2-Database console
simply you can create ~\test.mv.db file & add jdbc:h2:~/test in to JDBC URL in H2-Database console
Replace the default JDBC url of h2-console from application.properties to use JDBC Url=jdbc:h2:mem:testdb
Below is the application.properties
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=user
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
Add these two properties in application.property file
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testdb
type url: localhost:<portnumber>/h2-console in browser
You will get a page regrading login database
Remove existing JDBC url in the page and put this jdbc:h2:mem:testdb
my solution for this problem is:
in case you you didn't made a database folder in home directory (in windows under the: C:\Users*USERNAME\test* || in Linux: under the: ~/test) make it and add below lines to application.properties:
spring.jpa.hibernate.ddl-auto=create-drop
spring.datasource.url=jdbc:h2:~/test
spring.jpa.hibernate.ddl-auto=create-drop
it should help you to login.
((use blank username and password for H2))
Adding to answers, which mention auto-generated database name in Spring Boot 2.3+ – this is the way how to get the generated name into H2 Console programatically in Spring Boot, so that you can keep the generated database name. It basically gets the first H2 database source and updates/generates the H2 Console configuration file ~/.h2.server.properties, which is then loaded by H2 Console when it is first accessed.
Configure pom.xml to use H2 types directly:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>compile</scope>
</dependency>
Enable H2 Console in application.properties (true is a default value):
spring.h2.console.enabled=true
Code to use auto-generated database name:
import java.io.OutputStream;
import java.sql.Connection;
import java.util.List;
import java.util.Objects;
import java.util.Properties;
import java.util.stream.Collectors;
import javax.sql.DataSource;
import org.h2.engine.Constants;
import org.h2.store.fs.FileUtils;
import org.h2.util.SortedProperties;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Configuration;
@Configuration
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
public class H2ConsoleDatabaseAutoConfigurator {
@Autowired
public void configure(ObjectProvider<DataSource> dataSource) throws Exception
Properties properties = SortedProperties.loadProperties(Constants.SERVER_PROPERTIES_DIR + "/" + Constants.SERVER_PROPERTIES_NAME);
List<String> urls = dataSource.orderedStream().map((available) -> {
try (Connection connection = available.getConnection()) {
if (connection.getMetaData().getURL().startsWith("jdbc:h2:mem:")) {
return connection.getMetaData().getURL() + "|" + connection.getMetaData().getUserName();
} else {
return null;
catch (Exception ex) {
return null;
}).filter(Objects::nonNull).collect(Collectors.toList());
if (urls.size() > 0)
for (int i = 0;; i++)
String value = properties.getProperty(String.valueOf(i), null);
if (value == null || value.startsWith("Local H2|")) {
properties.setProperty(String.valueOf(i), "Local H2|org.h2.Driver|" + urls.get(0));
break;
OutputStream out = FileUtils.newOutputStream(
Constants.SERVER_PROPERTIES_DIR + "/" + Constants.SERVER_PROPERTIES_NAME, false);
properties.store(out, "H2 Server Properties");
out.close();
The console will contain the current H2 name as Local H2 menu entry:
The code is a composite of sources from H2 Console and Spring Boot H2 Console Autoconfiguration.
NOTE:->spring.datasource.url=jdbc:h2:mem:nilesh-->Should be same in console(JDBC URL)
application.properties
spring.h2.console.enabled=true
spring.datasource.platform=h2
spring.datasource.url=jdbc:h2:mem:nilesh
Adding JPA Dependency to pom.xml fixed this error for me.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Here is my application.properties file, just for your reference.
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:testapp
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
I am using Spring 2.7.3.
I had the same issue with mem:testdb not found. After trying out all the different solutions I could find in Stackoverflow, the only solution that worked for me was adding both "spring.datasource.url=jdbc:h2:mem:testdb" AND "spring.datasource.generate-unique-name=false" in my application properties file.
I thought that by adding just the "spring.datasource.url=jdbc:h2:mem:testdb" should stop spring from generating unique name everytime I restart the application but apparently not. Manually creating the test.mv file did not work for me either. Hope this helps.
Looks like everybody trying their own ways but solution to problem is NOT configuration but PHYSICAL.
See @Subramanian answer.
Somehow , If you want to connect via console, Spring is unable to create a PHYSICAL file testdb.mv.db in root folder, i.e C:/USERS/testdb.mv.db.
I went to C:/Users/SHEKHAR , and created a New > text file ( don't save it untill you rename it to testdb.mv.db or .mv.db.
Restart Springboot, "Test Connection" is Green and Connect , takes me to Console GUI.
–