2 回答

TA貢獻1841條經驗 獲得超3個贊
您可以將 H2 TCP 服務器作為 bean 啟動:
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<!-- <scope>runtime</scope> -->
</dependency>
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean(initMethod = "start", destroyMethod = "stop")
public Server h2Server() throws SQLException {
return Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", "9092");
}
}
然后使用以下參數(密碼 - 空)從您的 IDE 連接到它:
url: jdbc:h2:tcp://localhost:9092/mem:testdb
user: sa

TA貢獻1780條經驗 獲得超5個贊
您可以使用瀏覽器中的 Web 界面啟用 h2 Web 控制臺以訪問內存或文件數據庫中的 h2。
因此添加 application.properties 行:
spring.h2.console.enabled=true spring.h2.console.path=/h2-console
之后重新啟動您的 Spring Boot 應用程序并檢查http://localhost:8080/h2-console
您的瀏覽器。
添加回答
舉報