gpt4 book ai didi

Java Spring-boot 和内存中的 db H2。 db 不在 h2 web 控制台中

转载 作者:行者123 更新时间:2023-11-30 10:05:52 26 4
gpt4 key购买 nike

这是我的嵌入式数据库:

   public void init() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
db = builder
.setType(EmbeddedDatabaseType.H2)
.addScript("h2/create.sql")
.addScript("h2/insert.sql")
.build();
}

当我启动 JUnit 测试时,我在 Web 控制台中看不到在应用程序上下文初始化期间创建的数据库。

@Before
public void initTest() throws SQLException {
Server webServer = Server.createWebServer("-web", "-webAllowOthers", "-webPort", "8082");
webServer.start();
}

怎么了?

最佳答案

请引用:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html#boot-features-sql-h2-console

您可能想要使用以下属性:

spring.h2.console.enabled=true
spring.h2.console.path=/path/to/console

或者以编程方式启动服务器:

@Bean
public ServletRegistrationBean h2servletRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean(new WebServlet());
registration.addUrlMappings("/console/*");
registration.addInitParameter("webAllowOthers", "true");
return registration;
}

关于Java Spring-boot 和内存中的 db H2。 db 不在 h2 web 控制台中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55005916/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com