I found another way. I created the H2 Server
bean and added it to my SpringBoot Application. It looks like this:
// Start internal H2 server so can query from IDE
@Bean(initMethod = "start", destroyMethod = "stop")
public Server h2Server() throws SQLException {
return Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", "9092");
}
I also had the following on my application.properties
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.defer-datasource-initialization=true
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.sql.init.mode=always
# Initialise H2 with H2GIS for spatial support ? see schema-h2.sql also
spring.sql.init.platform=h2
spring.jpa.properties.hibernate.dialect=org.hibernate.spatial.dialect.h2geodb.GeoDBDialect
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
h2.tcp.enabled=true
In order to get my data.sql put into the tables in Intellij I had to make sure I used create-drop
and added the spring.sql.init.mode=always
Note: I was using the H2GIS dialect - but this has not so far caused any issues
The connection setup in Intellij
was still remote
with this string jdbc:h2:tcp://localhost:9092/mem:testdb
- dont forget to change the port to 9092
I the connection window in Intellij I also checked all tables under Schema. Then the tables are present for the H2 in mem database.