簡體   English   中英

如何在兩個應用程序之間共享一個 h2 數據庫?

[英]How do i share a h2 database between two application?

我一直在嘗試這樣做一段時間,我有一個管理應用程序和主應用程序,因此它們之間的唯一通信是返回書籍列表

            <img class="image-responsive shelf-book" th:src="#{adminPath}+@{/image/book/}+${book.id}+'.png'" width="100px" />

所以這里的管理員路徑是管理員的 URL,但由於他們不共享相同的數據庫,我無法在我的主應用程序中查看書籍

我在想 spring 雲服務器但沒有用,請問有什么建議嗎?

當我添加這個

jdbc.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:test:MODE=MySQL;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE
spring.datasource.username=sa
spring.datasource.password=

我收到這個錯誤

Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.h2.jdbc.JdbcSQLException: Feature not supported: "autoServerMode && inMemory" [50100-196]
        at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) ~[spring-jdbc-4.3.4.RELEASE.jar:4.3.4.RELEASE]
        at org.springframework.jdbc.datasource.init.DatabasePopulatorUtils.execute(DatabasePopulatorUtils.java:46) ~[spring-jdbc-4.3.4.RELEASE.jar:4.3.4.RELEASE]
        ... 63 common frames omitted
I added this below to both application and one app is running but the show this error
jdbc.driverClassName=org.h2.Driver
spring.datasource.url=jdbc:h2:~/test;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE 
spring.datasource.username=sa
spring.datasource.password=




 Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.h2.jdbc.JdbcSQLException: Database may be already in use: null. Possible solutions: close all other connection(s); use the server mode [90020-196]

我已經從一個應用程序中刪除了腳本任何關於為什么它說數據庫正在使用我希望他們共享數據庫的建議

在這兩個應用程序的配置文件中,您應該指出:

spring.datasource.url = jdbc:h2:~/test;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE

其中test是您的數據庫名稱。

如果您使用 Hibernate,也不要忘記:

spring.jpa.hibernate.ddl-auto = update

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM