简体   繁体   English

使用H2内存数据库进行Spring Boot Integration测试

[英]Spring Boot Integration test with H2 inmemory database

I tried various approach but I am confused now, I have spring boot application for which I'm writing integration test with inmemory h2 database. 我尝试了各种方法,但我现在很困惑,我有春季启动应用程序,我正在编写与内存h2数据库的集成测试。

this is application.yml 这是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

and I start the console by starting the server from here to test it in debug mode of test 我从这里启动服务器以在测试的调试模式下测试它来启动控制台

@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;
}

I'm able to view the console on 8081 port but I am not able to see the schema which I popultaed from yml file. 我能够在8081端口上查看控制台,但是我无法看到我从yml文件中弹出的模式。 Please help. 请帮忙。

我不确定为什么这不起作用但我通过java代码创建一个用于数据源的bean并从那里加载脚本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM