有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用maven配置HSQLDB

我正在开发一个Spring应用程序,其中所有内容都是用maven配置的(在pom.xml)。我的应用程序使用PostgreSQL数据库,但单元测试使用内存中的HSQLDB数据库

我刚刚遇到了TEXT列的问题,因为HSQLDB本机不支持这些列。在我的实体类中,我有:

private @Column(columnDefinition = "text") String propertyName;

这在Postgres中可以正常工作,但HSQLDB会生成以下错误:type not found or user lacks privilege: TEXT。表没有被创建,当然结果是我的大多数测试都失败了

我发现我需要activate PostgreSQL compatibility以便通过将sql.syntax_pgs设置为true来工作

我的问题是:我应该把这个设置放在哪里?我想把它放在pom.xml,因为所有的东西都在那里配置好了,但我不知道在哪里

例如,我有:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <argLine>-Dspring.profiles.active=test</argLine>
    </configuration>
</plugin>

我可以用这个设置添加一个<argLine>


共 (2) 个答案

  1. # 1 楼答案

    您可以在数据源配置中设置它,如下所示here

    <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
       <property name="driverClassName" value="org.hsqldb.jdbcDriver" />
       <property name="url" value="jdbc:hsqldb:mem:PUBLIC;sql.syntax_pgs=true" />
       <property name="username" value="sa" />
       <property name="password" value="" />
    </bean>
    
  2. # 2 楼答案

    添加hsqldb依赖项时,它使用默认连接属性。您可以根据需要在属性文件中或通过其他配置覆盖这些属性。您可以将“sql.syntax\u pgs=true”设置为HSQLDB连接url。例如,在弹簧启动的情况下,如下所示

    <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                  <argLine>-Dspring.datasource.url=jdbc:hsqldb:mem:PUBLIC;sql.syntax_pgs=true</argLine>
            </configuration>
    </plugin>