当我进入http://localhost:8080/h2-console
,然后输入sa
作为用户名,输入test
作为密码时,我得到了上面的图像。
我的application.properties
如下
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=test
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.orm.jdbc.bind=trace
spring.jackson.mapper.default-view-inclusion=true
而我的build. level
如下所示
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.5'
id 'io.spring.dependency-management' version '1.1.0'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-web'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'com.h2database:h2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
implementation 'com.google.code.gson:gson:2.8.6'
}
tasks.named('test') {
useJUnitPlatform()
}
我没有添加任何有关Spring Security的代码。我会不会设置错误?
这不是h2控制台登录页面,而是spring-security默认登录页面。
默认用户名是user
您会发现默认密码在开始时打印到控制台。
或者,您可以使用以下方式设置spring-security用户名和密码:
spring.security.user.name=user
spring.security.user.password=password