Boot在调试模式下阻止了H2控制台

Boot在调试模式下阻止了H2控制台

本文介绍了Spring Boot在调试模式下阻止了H2控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在WebIntegrationTest调试模式下访问H2-Console.但是,我注意到在调试测试时,Spring Boot会阻止H2控制台.似乎一旦达到断点,H2控制台也会被阻塞.我正在使用Spring Boot 1.3.1.RELEASE.

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.

以下测试中的每个断点都会导致H2控制台阻塞.在断点1中,将显示登录页面.然后,我按下登录按钮,但是直到让测试继续到下一个断点,什么都没有发生.在断点2中,我已登录并可以执行查询.但是只有当我要转到下一个断点时,查询结果才会出现.

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
}

WebIntegrationTest程序配置如下:

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 {

如何将H2-in-Memory DB与调试模式脱钩?

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

推荐答案

可以将Breakpoint配置为挂起整个VM或仅挂起一个线程.在IntelliJ中,您可以通过右键单击相应的断点来进行设置.我的断点被配置为挂起整个VM,因此每个断点也被阻止访问H2-Console.

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.

这篇关于Spring Boot在调试模式下阻止了H2控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 10:31