Reputation: 297
I have a Spring Boot project that uses H2. No matter what I set my database name to in my application.properties file, whey I bring up the H2 console, the name of the database is "test". I can log in and see my schema, but can't set the name of the database to anything but "test". No matter what name I use in the application.properties file, the name on the H2 console is "test".
My POM is
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.repository</groupId>
<artifactId>repository</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>repository</name>
<description>repository project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
My application.properties file is
spring.datasource.url=jdbc:h2:file:~/test
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
spring.h2.console.path=/h2-console
spring.h2.console.enabled=true
spring.jpa.show-sql=true
server.port=8081
Upvotes: 1
Views: 9755
Reputation: 111
You need to set "generate-unique-name" to false and set name as below:
spring.datasource.generate-unique-name=false
spring.datasource.name=my-new-db-name
Upvotes: 7
Reputation: 96
If still the problem persists, you should try change other settings for example: port # or "spring.h2.console.path=/h2-console" -> "spring.h2.console.path=/h2" to see if it takes effect after the app restart. If not then probably something is wrong with your project setup.
spring.datasource.url=jdbc:h2:file:c:/temp/rcp_h2
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
spring.h2.console.path=/h2-console
spring.h2.console.enabled=true
spring.jpa.show-sql=true
server.port=8081
Upvotes: 0
Reputation: 2375
The followingis the reference to database name - file:~/test
. You need to change test to something else.
Upvotes: 0