Spring Boot 指南说我可以获得 H2 控制台,但它对我不起作用。
http://localhost:8080/h2/ Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Wed Oct 26 12:31:46 BST 2016 There was an unexpected error (type=Not Found, status=404). No message available
我创建了一个
application.properties
文件如下spring.h2.console.enabled=true
spring.h2.console.path=/h2
我的项目基于 this
默认路径
/h2-console
也不起作用。我找到了另一个答案,通过添加到
Application.java
解决了问题。 : @Bean
public ServletRegistrationBean h2servletRegistration() {
ServletRegistrationBean registration = new ServletRegistrationBean(new WebServlet());
registration.addUrlMappings("/h2/*");
return registration;
}
我的一切
application.properties
文件被忽略。我试过添加:spring.datasource.url=jdbc:h2:file:~/portal;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
但是数据库仍然只在内存中创建。
最佳答案
检查您是否在 application.properties 中设置了基本路径。
例如,如果您有一个设置
server.contextPath=/api
您访问 h2 控制台下
http://localhost:8080/api/h2-console
很明显,但对我来说就是这样
关于gradle - Spring Boot JPA H2 控制台未运行,application.properties 文件被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40261302/