Search code examples
postgresqlspring-bootgithubspring-datagithub-actions

Spring Data JPA application with Github Actions CI


I'm trying to set up Github Actions CI with my Spring Boot project that uses Spring Data JPA. The problem is that the Github server that runs Spring won't build properly since there is no database connected on that end. I was wondering if there is a way to either isolate the app to not need a database when running Actions, or create a dummy database that the app can connect to?

I've tried to provide a postgres service container on github actions but since my Spring Boot app's database connection details is on application.properties, I don't think it can communicate with the service container's postgres.


Solution

  • You can use multiple application.properties files ("application-dev.properties, application-prod.properties etc.) for various environments. For example, using an H2 in-memory database for testing, dev, prod and so-on.

    Then you can use mvn -B clean package -P {flag} --file pom.xml in your github actions to run with the in-mem database.

    I think this answer may be helpful to you.