我有一个使用H2的Spring Boot项目。无论我在我的application.properties文件中设置我的数据库名称,乳清我调出H2控制台,数据库的名称是“test”。我可以登录并查看我的架构,但不能将数据库的名称设置为“test”。无论我在application.properties文件中使用什么名称,H2控制台上的名称都是“test”。
我的POM是
<?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>
我的application.properties文件是
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
答案 0 :(得分:0)
以下是对数据库名称的引用 - file:~/test
。您需要将测试更改为其他内容。
答案 1 :(得分:0)
如果问题仍然存在,则应尝试更改其他设置,例如:将port#或“ spring.h2.console.path = / h2-console”->“ spring.h2.console.path = / h2”更改为查看应用重新启动后是否生效。如果不是,那么您的项目设置可能有问题。
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