【发布时间】:2017-03-22 05:28:18
【问题描述】:
我尝试了各种方法,但现在我很困惑,我有 spring boot 应用程序,我正在为它编写与 inmemory h2 数据库的集成测试。
这是 application.yml
spring.profiles: test
spring.datasource:
url: jdbc:h2:mem:AZ;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
username: sa
password:
driver-class-name: org.h2.Driver
platform: h2
# enable H2 web console and set url for web console
# http://localhost:8080/console
h2:
console:
enabled: true
path: /console
schema: schema.sql
data: data.sql
我通过从这里启动服务器来启动控制台以在测试的调试模式下对其进行测试
@Bean
public ServletRegistrationBean h2servletRegistration() throws SQLException {
Server webServer = Server.createWebServer("-web", "-webAllowOthers", "-webPort", "8081");
webServer.start();
ServletRegistrationBean registration = new ServletRegistrationBean(new WebServlet());
registration.addUrlMappings("/console/*");
return registration;
}
我可以在 8081 端口上查看控制台,但我看不到我从 yml 文件中填充的架构。请帮忙。
【问题讨论】:
-
尝试使用模式,例如: MODE=MYSQL in your url
-
你能看到正在加载到数据库中的 sql 吗?
-
@GurinderSPanesar 没有运气
-
@AdamSmith 我正在尝试通过控制台查看此内容,我无法从那里看到,如何检查?
-
我有一个疑问,我这样做对吗?我正在启动服务器,并且在 yml 中也有配置?如果这会创建两个不同的内存数据库?
标签: java spring spring-boot integration-testing h2