这是我现在的配置。我想在生产中使用休眠空间与 postgis 一起工作。
spring:
profiles: production
datasource:
platform: postgres
url: jdbc:postgresql://192.168.99.100:5432/dragon
username: dragon
password: dragon
database:
driverClassName: org.postgresql.Driver
jpa:
database: POSTGRESQL
database-platform: org.hibernate.spatial.dialect.postgis.PostgisDialect
show-sql: true
hibernate:
ddl-auto: update
---
spring:
profiles: development
datasource: SpatialInMemoryDb
jpa:
database-platform: org.hibernate.spatial.dialect.h2geodb.GeoDBDialect
hibernate:
ddl-auto: create-drop
对于测试,所有发现都是 h2gis 项目。
public class SpatialInMemoryDb extends SingleConnectionDataSource{
public SpatialInMemoryDb() {
setDriverClassName("org.h2.Driver");
setUrl("jdbc:g2:mem:test");
setSuppressClose(true);
}
@Override
public Connection getConnection() throws SQLException {
System.out.println("************");
Connection connection = super.getConnection();
try (Statement st = connection.createStatement()) {
// Import spatial functions, domains and drivers
// If you are using a file database, you have to do only that once.
CreateSpatialExtension.initSpatialExtension(connection);
} catch (Exception e) {
e.printStackTrace();
}
return connection;
}
不确定它是否适用于 geodbdialect 或 postgisdialect,尽管它似乎非常接近 postgisdialect。
无论如何,有人可以推荐一些简单的解决方案吗?