<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
src/main/resources/schema.sql
spring.sql.init.mode=always
spring.datasource.url=jdbc:h2:file:/tmp/vuls
spring.datasource.username=sa
spring.datasource.password=password
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.hibernate.ddl-auto=none
I've been all over SO and the correct procedure for H2 database creation apparently changes with every Spring Boot release, because there are various and sundry answers out there that aren't working for me.
It seems like you're encountering issues with initializing your H2 database using the
schema.sqlfile in your Spring Boot application. Here are a few things to check:application.propertiesorapplication.ymlfile contains the correct properties to specify the SQL script and other database configuration details.To use H2 embedded:
Then to access to h2 console :
http://localhost:8080/h2-console
Check Logs: Look for any error messages or warnings related to database initialization in your application logs. This can provide valuable insights into why the schema initialization is not happening as expected. Pay attention to any exceptions or warnings related to database connectivity or schema initialization.
Dependencies: Double-check that your project dependencies are correctly configured. Since you're using H2 as an embedded database, ensure that the H2 dependency is included in your project's build configuration (
pom.xmlfor Maven orbuild.gradlefor Gradle).If you continue to encounter problems, providing specific error messages or logs can help in diagnosing the issue further.