【发布时间】:2017-03-08 18:17:28
【问题描述】:
Spring Boot 指南说我可以获得 H2 控制台,但它不适合我。
http://localhost:8080/h2/ Whitelabel 错误页面 此应用程序没有显式映射 /error,因此您将其视为后备。 2016 年 10 月 26 日星期三 12:31:46 BST 出现意外错误(类型=未找到,状态=404)。 没有可用的消息
我创建了一个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在哪里以及您使用的是哪个版本的 Spring Boot。 -
javaworkspace\gs-accessing-data-rest-initial\src\main\java\hello\application.properties和org.springframework.boot:spring-boot-gradle-plugin:1.4.1.RELEASE -
那是错误的...它是一个非 java 源代码,所以它会被忽略它应该放在
src\main\resources...旁边它必须在 te 根而不是子包中。
标签: gradle spring-boot h2