如果我用
@SpringBootTest
有没有办法访问H2控制台?我有一个可以访问H2数据库的测试(成功),但是如果我想自己检查数据库,我该怎么做呢?
我首先用
webEnvironment=DEFINED_PORT
和
http://localhost:8080/
响应HTTP,但什么都没有
http://localhost:8080/h2-console/
仍然以404回应。
我尝试通过向
application.properties
:
spring.h2.console.enabled=true
spring.h2.console.path=/h2
这似乎没有效果。仍为404s at
/h2-console
和
/h2
.
H2控制台似乎是通过自动配置进入的,所以我使用
-Ddebug
,我可以看到,尽管在应用程序中启用了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)
似乎有某种机制正在覆盖值或忽略
应用属性
运行测试时。
Spring Boot Test是否未启动控制台?有没有办法说服它这样做?