Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot is blocking H2 Console in Debug Mode

I'm trying to access the H2-Console during a WebIntegrationTest in debug mode. However, I noticed that Spring Boot is blocking the H2-console when I'm debugging the test. It seems as soon as a breakpoint is reached, the H2-console is blocked as well. I'm working with Spring Boot 1.3.1.RELEASE.

Each breakpoint in the following test causes to block the H2-console. In breakpoint 1, the login page appears. I then press to login button but nothing happens until I let continue the test to the next breakpoint. In breakpoint 2, I'm logged in and can execute a query. But only when I'm going to the next breakpoint, the query results appear.

@Test
public void whenGetById_thenCorrectId() throws InterruptedException {
    // do some stuff
    // breakpoint 1
    Thread.sleep(1000);
    // breakpoint 2
    Thread.sleep(1000);
    // breakpoint 3
}

The WebIntegrationTest ist configured as follows:

@ActiveProfiles("local,unittest")
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = MyApplication.class)
@WebIntegrationTest({"spring.h2.console.enabled=true", "server.port=8080"})
public class MyResourceTest {

How can I decouple the H2-in-memory DB from the debug mode?

like image 624
René Winkler Avatar asked Feb 03 '16 13:02

René Winkler


People also ask

How do I access H2 console with Spring Security?

Accessing the H2 Console By default, the H2 console is not enabled in Spring. Then, after starting the application, we can navigate to http://localhost:8080/h2-console, which will present us with a login page. The web console has an auto-complete feature that suggests SQL keywords.

How do I enable console H2?

H2 Console: By default, the console view of the H2 database is disabled. Before accessing the H2 database, we must enable it by using the following property. Once we have enabled the H2 console, now we can access the H2 console in the browser by invoking the URL http://localhost:8082/h2-console.


1 Answers

Breakpoint can be configured to suspend the whole VM or only a single thread. In IntelliJ you can set this via right-click on the respective breakpoint. My breakpoints were configured to suspend the whole VM and so each breakpoint also blocked to access the H2-Console.

enter image description here

like image 198
René Winkler Avatar answered Oct 03 '22 01:10

René Winkler