2

This is my embedded database:

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

When I launch JUnit tests, I don't see in web console, the db that was created during application context intialization.

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

What's wrong?

1
  • 1
    Did you try this? spring.h2.console.enabled=true Commented Mar 5, 2019 at 15:32

1 Answer 1

1

Please refer: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html#boot-features-sql-h2-console

You might want to use the following properties:

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

Or start server programmatically:

@Bean
public ServletRegistrationBean h2servletRegistration() {
    ServletRegistrationBean registration = new ServletRegistrationBean(new WebServlet());
    registration.addUrlMappings("/console/*");
    registration.addInitParameter("webAllowOthers", "true");
    return registration;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.