The reason we should or might want to test a Neo4j database connection is because setting the credentials in the application.properties
file does not actually test the connection. This needs to be done at runtime because they aren’t config properties.
There are a few different ways to go about testing a Neo4j database connection from a Spring Boot application:
-
Write application functionality (domain, repository, controller classes) that utilize the connection.
-
Use a CommandLineRunner with the driver bean and use the
verifyConnectivity()
method. -
Write a test for that uses the
verifyConnectivity()
method.
This repository accompanies a blog post that explains the code.