[英]How can I calculate Shortest Path through Neo4j in my Spring Boot through localhost and Docker?
I have a problem about calculating the shortest path through Neo4j in my Spring Boot example.我在 Spring Boot 示例中计算通过 Neo4j 的最短路径时遇到问题。
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.
但是,在 ShortestPathController 中定义的这两个方法不能工作。
Here are the issues shown below.以下是显示的问题。
Edited已编辑
1 ) I cannot run all test methods in AppApplicationTests.java 1 )我无法在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 ) 2)我不知道,因为我无法运行所有测试方法,如果有很多城市及其路线像这个资源( 链接)
How can I fix it?我该如何解决?
Here is my GitHub repository : Project Link这是我的 GitHub 存储库:项目链接
Here is my docker-compose.yml file这是我的 docker-compose.yml 文件
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:
Part 1: This is just a warning.第 1 部分:这只是一个警告。 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.第 2 部分:@jose_bacoy 所说的。 Behind the link are informations about how to add APOC in Desktop, Server or Docker deployment.
链接后面是有关如何在桌面、服务器或 Docker 部署中添加 APOC 的信息。 Test your query (or even a reduced version of it) in the shell/browser to ensure it is activated correctly.
在 shell/浏览器中测试您的查询(甚至是它的简化版本),以确保它被正确激活。
Part 2 (again but different topic): You cannot return PathValue
in a repository.第 2 部分(同样是不同的主题):您不能在存储库中返回
PathValue
。 If you want to use the Java driver's type, please use SDN's Neo4jClient
for interaction.如果要使用Java驱动的类型,请使用SDN的
Neo4jClient
进行交互。 SDN documentation / Neo4jClient SDN 文档 / 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. (编辑并添加) Docker compose:我无法使用其他语法提供数组,所以基本上这将在容器启动时自动加载插件。 You can check if the APOC library is available via
CALL dbms.procedures()
in the shell or browser.您可以通过 shell 或浏览器中的
CALL dbms.procedures()
检查 APOC 库是否可用。 This is what you should do first .这是你首先应该做的。
environment:
- NEO4J_AUTH=neo4j/secret
- NEO4JLABS_PLUGINS=["apoc"]
You need to ensure that APOC library is installed in your Neo4j server.您需要确保在 Neo4j 服务器中安装了 APOC 库。 Please follow this installation procedure.
请遵循此安装程序。
https://neo4j.com/labs/apoc/4.0/installation/#neo4j-server
Then update your conf file to whitelist that function.然后更新您的 conf 文件以将该功能列入白名单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.