java - Spring Boot 数据库持久存在于其他计算机上
问题描述
我希望我的 Spring Boot 应用程序使用我输入的示例数据在其他计算机上运行。目前,我可以退出 IDE 并重新启动应用程序,它工作正常,但是当我上传我的项目供同事下载时,他们没有任何可以访问的数据。如何实现可以上传项目,让使用该应用程序的每个人都可以访问我之前输入的测试数据的功能?
我在主文件夹中的 application.properties:
spring.h2.console.enabled=true
spring.h2.console.path=/h2
spring.datasource.url=jdbc:h2:~/spring-boot-h2-db;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
spring.jpa.hibernate.ddl-auto=update
我的 build.gradle:
plugins {
id 'org.springframework.boot' version '2.1.3.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
group = 'de.hsba.bi.traveldiary'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'com.h2database:h2'
implementation 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:2.3.0'
implementation 'org.springframework.boot:spring-boot-starter-web-services'
implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'
runtime 'com.h2database:h2'
}
提前非常感谢!
解决方案
你有多种选择
1,如果超过 1 个开发人员正在开发一个应用程序,您应该在任何人都可以访问的服务器或计算机上创建一个共享数据库,例如 MySql
2,如果您想使用 h2,您可以使用应用程序启动来填充它: https ://docs.spring.io/spring-boot/docs/current/reference/html/howto-database-initialization.html
3,我猜这是一个存储在您主目录中的文件中的 h2 db,因此您也可以复制它<-我不确定这是否有效,但理论上应该没问题
推荐阅读
- multithreading - 多线程程序需要多少个指令计数器?
- visual-studio-code - 在哪里可以找到关于 VS Code 中禁用的内置扩展的设置?
- swift - 如何在 macOS 上将 iPhone 作为 AVCaptureDevice?
- arrays - 在scala中过滤排序数组
- php - php中的数组键和值
- python - 将括号内的文本提取到熊猫数据框中
- amazon-web-services - Metric Math - 影响自动缩放的 SUM 动态指标
- api - 从源 [本地] 访问 [服务器] 上的 XMLHttpRequest 已被 CORS 策略阻止
- django - 如何从 Django 中具有多字段的 HTML 表单将数据发布到数据库?
- node.js - 我如何将所有用户名从 firestore 传递给 ejs 以显示在我的 users.ejs 上