Reputation: 321
I have gradle spring boot app with h2 database in eclipse.When i try to login to console only default username:sa
and empty password works even though i added config in application properties.Why?
My application.properties
file:
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.data-username=test
spring.datasource.data-password=test
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
Console:
2020-06-27 22:49:21.425 INFO 13960 --- [ main] o.s.b.a.h2.H2ConsoleAutoConfiguration
: H2 console available at '/h2-console'. Database available at 'jdbc:h2:mem:testdb'
Dependencies in build.gradle
:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'com.h2database:h2'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-jaxb:2.9.0'
implementation 'com.squareup.okhttp3:okhttp:4.7.2'
implementation("com.squareup.okhttp3:logging-interceptor:4.7.2")
implementation('javax.xml.bind:jaxb-api:2.3.0')
implementation('javax.activation:activation:1.1')
implementation('org.glassfish.jaxb:jaxb-runtime:2.3.0')
}
Upvotes: 3
Views: 2699
Reputation: 5063
It still works, because you are setting your username and password wrong.
According to the documentation, property spring.datasource.data-username
sets
Username of the database to execute DML scripts (if different).
and spring.datasource.data-password
sets
Password of the database to execute DML scripts (if different).
You need to set spring.datasource.username
and spring.datasource.password
.
Your config file should look like:
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=test
spring.datasource.password=test
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.h2.console.enabled=true
Upvotes: 3