xxxxxxxxxx
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
xxxxxxxxxx
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto= update
spring.h2.console.enabled=true
# default path: h2-console
spring.h2.console.path=/h2-ui
xxxxxxxxxx
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
<version>1.4.199</version>
</dependency>
xxxxxxxxxx
// use it only for testing (recommended)
// make sure to put schema and data .sql script inside src/main/resources
// pom.xml (add dependencies)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
// application.properties
logging.level.org.springframework[.jdbc.datasource.init.ScriptUtils]=debug // allows to see output when data is loaded as log
spring.h2.console.enabled=true // allows us to access the h2 database console through "localhost:8080/h2-console"
spring.datasource.url=jdbc:h2:mem:testdb // use in-memory database (put jdbc:h2:mem:testdb in URL console)
// NOTE: Any .sql file inside src/main/resources will now be automatically picked up by h2
xxxxxxxxxx
If one of your Test Class works but the remaining
classes in test suite does not work.
(Fails when running mvn clean install)
Then add the following annotation on every test class.
@AutoConfigureTestDatabase(replace = Replace.ANY)