代码之家  ›  专栏  ›  技术社区  ›  valik

如何在两个应用程序之间共享h2数据库?

  •  0
  • valik  · 技术社区  · 9 年前

    我已经尝试了一段时间,我有一个管理应用程序和主应用程序

                <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]
    

    1 回复  |  直到 9 年前
        1
  •  4
  •   Sedat Gokcen    9 年前

    在两个应用程序的配置文件中,您应该指出:

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

    哪里 test

    如果使用Hibernate,也不要忘记:

    spring.jpa.hibernate.ddl-auto = update