data.sql not loading in springboot

  1. Check file location: Ensure that the data.sql file is located in the correct directory. By default, Spring Boot looks for the data.sql file in the /resources directory.

  2. Verify file name and extension: Check that the file is named correctly as data.sql and has the .sql extension. Ensure there are no typos in the file name or extension.

  3. Check application.properties: Verify that the property "spring.datasource.initialization-mode" is not set to "never" in the application.properties file. If it is set to "never," the data.sql file will not be executed.

  4. Review application.properties location: Confirm that the application.properties file is located in the /resources directory, and it is properly configured to enable the execution of data.sql.

  5. Check for SQL syntax errors: Ensure that the data.sql file does not contain any syntax errors. Any errors in the SQL commands can prevent the file from being loaded.

  6. Enable logging: Enable Spring Boot logging to see if there are any error messages related to the data.sql file not being loaded. This can provide insights into the issue.

  7. Verify dependencies: Check that the necessary dependencies for Spring Boot and Spring Data are correctly included in the project's build file (e.g., pom.xml for Maven or build.gradle for Gradle).

  8. Test with H2 console: If using an H2 in-memory database, test the data.sql file by accessing the H2 console to see if the data is loaded into the database.

  9. Use @Sql annotation: If the data.sql file is not being picked up, consider using the @Sql annotation in a test class to explicitly specify the data.sql file for execution during testing.

  10. Check for conflicting scripts: Ensure that there are no conflicting scripts that may be overriding the data.sql file, such as import.sql or schema.sql.

  11. Verify Spring Boot version: Check if there are any specific issues or changes related to data.sql loading in the version of Spring Boot being used, and consider updating to a newer version if necessary.