I have a problem about calculating the shortest path through Neo4j in my Spring Boot example.
After adding some cities with its route, I want to calculate their shortest path in terms of their connection and their duration. However, these two methods which defined in ShortestPathController cannot work.
Here are the issues shown below.
Edited
1 ) I cannot run all test methods in AppApplicationTests.java
org.neo4j.driver.exceptions.AuthenticationException: The client is unauthorized due to authentication failure.
2 ) I have no idea as I cannot run all test methods what if there are many cities and its route like this resource (Link)
How can I fix it?
Here is my GitHub repository : Project Link
Here is my docker-compose.yml file
version: '3'
services:
neo4j-db:
image: neo4j:4.3
container_name: app-neo4j-db
ports:
- 7474:7474
- 7687:7687
volumes:
- $HOME/neo4j/data:/data
- $HOME/neo4j/logs:/logs
- $HOME/neo4j/import:/import
- $HOME/neo4j/plugins:/plugins
environment:
NEO4J_AUTH: "neo4j/123456"
NEO4JLABS_PLUGINS: '["apoc"]'
NEO4J_dbms_security_procedures_unrestricted: apoc.\*,gds.\*
dbms_connector_bolt_listen__address: neo4j-db:7687
dbms_connector_bolt_advertised__address: neo4j-db:7687
healthcheck:
test: cypher-shell --username neo4j --password 123456 'MATCH (n) RETURN COUNT(n);' # Checks if neo4j server is up and running
interval: 10s
timeout: 10s
retries: 5
app:
image: 'springbootneo4jshortestpath:latest'
build:
context: .
dockerfile: Dockerfile
container_name: SpringBootNeo4jShortestPath
depends_on:
neo4j-db:
condition: service_healthy # Wait for neo4j to be ready
links:
- neo4j-db
environment:
NEO4J_URI: bolt://neo4j-db:7687
NEO4J_USER: neo4j
NEO4J_PASSWORD: 123456
volumes:
app-neo4j-db:
2
Answers
You need to ensure that APOC library is installed in your Neo4j server. Please follow this installation procedure.
Then update your conf file to whitelist that function.
Part 1: This is just a warning. In most cases you would not be happy with unbound relationships because the paths can quickly grow in numbers and the server has to keep all possible combination in memory before you will get it.
Part 2: What @jose_bacoy says. Behind the link are informations about how to add APOC in Desktop, Server or Docker deployment. Test your query (or even a reduced version of it) in the shell/browser to ensure it is activated correctly.
Part 2 (again but different topic): You cannot return
PathValue
in a repository. If you want to use the Java driver’s type, please use SDN’sNeo4jClient
for interaction. SDN documentation / Neo4jClient(Edit and added)
Docker compose:
I could not make it work to provide an array with the other syntax, so basically this will auto-load the plugin on container start.
You can check if the APOC library is available via
CALL dbms.procedures()
in the shell or browser.This is what you should do first.