如果我正在运行测试@SpringBootTest
有什么办法可以访问H2控制台吗?我有一个访问 H2 数据库(成功)的测试,但如果我想自己检查数据库,我该怎么做?
我首先运行测试webEnvironment=DEFINED_PORT
and http://localhost-8080.com/ http://localhost:8080/响应 HTTP,但没有任何响应http://localhost:8080/h2-console/ http://localhost:8080/h2-console/仍然返回 404。
我尝试通过添加值来显式打开控制台application.properties
:
spring.h2.console.enabled=true
spring.h2.console.path=/h2
这似乎没有什么效果。仍然是 404/h2-console
and /h2
.
H2控制台似乎是通过自动配置进来的,所以我使用打开了自动配置报告-Ddebug
,我可以看到,尽管 application.properties 中启用了启用标志,但它被视为关闭:
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 Boot Test 不启动控制台吗?有什么办法可以说服它这样做吗?
好的,我可以使用以下注释(在 Kotlin 中)让它显示:@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT, properties = arrayOf("spring.h2.console.enabled=true"))
即使这样,控制台仍然处于/h2-console
,所以它显然也忽略了控制台路径。我大概可以通过添加另一个属性来控制它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)