Spring boot 运行SpringBootTest时访问H2控制台

Spring boot 运行SpringBootTest时访问H2控制台,spring-boot,spring-boot-test,Spring Boot,Spring Boot Test,如果我使用@SpringBootTest运行测试,有没有办法访问H2控制台?我有一个访问H2数据库的测试(成功),但是如果我想自己检查数据库,我怎么能 我首先使用webEnvironment=DEFINED_PORT运行测试,并响应HTTP,但是仍然没有任何东西响应404 我尝试通过向应用程序添加值来显式打开控制台。属性: spring.h2.console.enabled=true spring.h2.console.path=/h2 这似乎没有效果。在/h2控制台和/h2仍有404s H2

如果我使用
@SpringBootTest
运行测试,有没有办法访问H2控制台?我有一个访问H2数据库的测试(成功),但是如果我想自己检查数据库,我怎么能

我首先使用
webEnvironment=DEFINED_PORT
运行测试,并响应HTTP,但是仍然没有任何东西响应404

我尝试通过向
应用程序添加值来显式打开控制台。属性

spring.h2.console.enabled=true
spring.h2.console.path=/h2
这似乎没有效果。在
/h2控制台
/h2
仍有404s

H2控制台似乎是通过自动配置进入的,因此我使用
-Ddebug
打开了自动配置报告,我可以看到,尽管application.properties中的enabled标志处于打开状态,但它被视为关闭状态:

H2ConsoleAutoConfiguration: 
      Did not match:
          - @ConditionalOnProperty (spring.h2.console.enabled=true) did not find property 'enabled' (OnPropertyCondition)
      Matched:
         - @ConditionalOnClass found required class 'org.h2.server.web.WebServlet'; @ConditionalOnMissingClass did not find unwanted class (OnClassCondition)
         - found WebApplicationContext (OnWebApplicationCondition)
运行测试时,似乎有某种机制正在重写值或忽略
application.properties
中的值


Spring引导测试是否不启动控制台?有什么方法可以说服它这样做吗?

好的,我可以让它显示以下注释(在Kotlin中):
@SpringBootTest(webEnvironment=SpringBootTest.webEnvironment.DEFINED_PORT,properties=arrayOf(“spring.h2.console.enabled=true”)

即使这样,控制台仍然位于
/h2 console
,因此它显然也忽略了控制台路径。我大概可以通过添加另一个属性来控制它