使用maven配置HSQLDB

时间:2016-09-23 12:54:56

标签: java spring hibernate 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 个答案:

答案 0 :(得分:1)

添加hsqldb依赖项时,它使用默认连接属性。您可以根据您的要求在属性文件中或通过其他配置覆盖这些属性。您可以将“sql.syntax_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>

答案 1 :(得分:0)

您可以在给定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>