我正在开发一个 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>
用这个设置?
最佳答案
当您添加 hsqldb 依赖项时,它会使用默认连接属性。您可以根据您的要求在属性文件中或通过其他配置覆盖这些属性。您可以将“sql.syntax_pgs=true”设置为HSQLDB连接url。例如,在 Spring Boot 的情况下,如下所示。
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Dspring.datasource.url=jdbc:hsqldb:mem:PUBLIC;sql.syntax_pgs=true</argLine>
</configuration>
</plugin>
关于java - 使用maven配置HSQLDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39661332/