gpt4 book ai didi

java - Spring Boot 通过 Derby 启用特定嵌入式数据库 HSQL

转载 作者:行者123 更新时间:2023-11-30 07:41:48 25 4
gpt4 key购买 nike

我正在尝试在 weblogic 服务器上部署我的应用程序,我的应用程序有一个内存数据库,并且由于我将 HSQLDB 用于 JUNIT,所以我想保留 HSQL 作为我的内存数据库(主要是比 derby 性能稍好一些) )。由于weblogic已经有了derby,当我尝试部署应用程序时,derby正在启动,而不是HSQL。经过初步调查,我发现由于 Derby 是在 EmbeddedDatabaseConnection.java 中的 HSQL 之上定义的,因此 Derby 数据库首先启动。是否有任何特定的配置,我可以在其中显式地将数据库类型嵌入到 HSQL 而不是允许 Spring Boot 基于库/类启动数据库

最佳答案

我能想到的第一个尝试是从类路径中删除 Derby 并只保留 HSQL。 Spring Boot docs :

If HSQLDB is on your classpath, and you have not manually configured any database connection beans, then we will auto-configure an in-memory database.

如果这不是一个选项,您可以指定

  1. connection type for Hibernate (JPA) :

An embedded database is detected by looking at the Connection type: hsqldb, h2 and derby are embedded, the rest are not.

  • HSQL 明确作为主要数据源:

    @Configuration
    public class DataSourceConfig {
    @Bean
    public DataSource dataSource() {
    return new EmbeddedDatabaseBuilder()
    .setType(EmbeddedDatabaseType.HSQL)
    .build();
    }
    }
  • 定义spring.datasource.type属性

  • 关于java - Spring Boot 通过 Derby 启用特定嵌入式数据库 HSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34567082/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com