java - 当我尝试连接 ht2 数据库时,找不到数据库“mem:”,并且 IFEXISTS=true
问题描述
我有具有 4 个微服务的基本 Spring Boot 应用程序。发现服务、Api 网关服务 (Zuul)、UsersMicorservise 和 Accounts 微服务
我正在尝试将 h2 内存数据库添加到我的用户服务中,但是当我加载 h2 控制台并按下连接时,我收到了此消息
这些是我的 application.properties
server.port=${PORT:0}
spring.application.name=users-ws
eureka.client.serviceUrl.defaultZone = http://localhost:8010/eureka
spring.devtools.restart.enabled = true
eureka.instance.instance-id=${spring.application.name}:${spring.application.instance_id:${random.value}}
# H2
spring.h2.console.enabled=true
spring.h2.console.settings.web-allow-others=true
spring.datasource.url=jdbc:h2:mem:test
这是我的 pom.xml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.8.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.appsdeveloperblog.photoapp.api.users</groupId>
<artifactId>PhotoAppApiUsers</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>PhotoAppApiUsers</name>
<description>Users microservice</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR3</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
解决方案
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:mem:test;IFEXISTS=FALSE;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.h2.console.path=/h2-console
或者
降级到 1.3.170
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.170</version>
<scope>runtime</scope>
</dependency>
推荐阅读
- docker - 如何将 mosquitto docker 日志挂载到本地 pc
- latex - 强制引用在乳胶的最后一页
- azure-service-fabric - 在 Service Fabric 中运行后台任务 - ASP.NET Core HostedService 还是使用 StatelessService.RunAsync()?
- r - 如何使我的 R 脚本对崩溃具有鲁棒性?
- mysql - 从同一数据库但不同应用程序(例如 Django 和 Node js)验证同一用户的最佳方法是什么?
- python - 在 matplotlib 图中完全绘制轴
- azure-devops - 将经典 azure devop 发布管道迁移到 yaml 的更简单方法?
- html - 页面缺少 HTML doctype,因此触发了 quirks 模式
- javascript - 在Javascript中用反斜杠分割字符串
- sql - MariaDB 数据透视表性能