【发布时间】:2017-07-28 20:59:19
【问题描述】:
我在我的应用程序属性文件中使用了以下设置。但仍然无法在 h2 控制台中看到我的表格。
application.properties
logging.level.org.springframework.web=INFO
spring.datasource.url=jdbc:h2:mem:challenge;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MV_STORE=FALSE
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.schema=classpath:/schema.sql
spring.datasource.data=classpath:/data.sql
spring.h2.console.enabled=true
spring.h2.console.path=/h2
server.port = 8080
我在 H2 控制台的 JDBC URL 中使用字符串 jdbc:h2:mem:challenge;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MV_STORE=FALSE 登录。但是我没有看到任何表格
以下是我的 Gradle 文件
buildscript {
ext {
springBootVersion = '1.4.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'challenge'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-jdbc')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
runtime('org.springframework.boot:spring-boot-devtools')
runtime('com.h2database:h2')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
以下是为我的 Spring Boot 应用实现 Springsecurity 的类
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/h2/*").permitAll();
http.csrf().disable();
http.headers().frameOptions().disable();
}
}
【问题讨论】:
-
感谢您的 cmets。但是我确实阅读了所有其他帖子,它们都没有解决我的问题。我已经启动了我的 Spring-boot 应用程序,它基本上是一个连接到 H2 数据库并获取所有信息的 Web 服务。网络服务正在显示信息,但是当我登录 H2 控制台时,我看不到任何表或数据库
-
请出示你的 pom 或 gradle
-
@georgesvan : 更新了我的 gradle 文件
-
@Vinayak 请参阅下面的答案 - 似乎在创建 H2 内存数据库时,您在属性文件中提供的数据库名称将被忽略,默认情况下命名为
testdb。当 Spring 应用启动时,URL 和用户名应该输出到控制台。
标签: spring spring-boot h2