gradle - Spring Boot JPA H2 控制台未运行,application.properties 文件被忽略

标签 gradle spring-boot h2

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/

相关文章:

android - 如何确定 kotlin-multiplatform 项目中的构建类型

gradle - 如何使用 gradle 将 .properties 文件添加到我的 WAR 中?

spring - 在具有相似 ID 的 Spring Boot 中加入没有外键的两个表

spring-boot - spring.h2.console.settings.web-allow-others 不适合我禁用访问

spring - Spring Boot 应用程序中的 H2 架构为空

gradle - LibGDX 构建模型错误

android - 为什么Android Studio在单个字母更改并运行后构建整个项目

java - 简单的 WebMvcTest 失败,Spring Boot 缺少 SpringBootConfiguration

java - 如何让Kafka消费者从特定主题分区读取Spring Boot

java - 如何使用 H2 的 CSVREAD() 函数/查询在 WAR 中访问 CSV 文件?