简体   繁体   English

如何通过 localhost 和 Docker 在 Spring Boot 中通过 Neo4j 计算最短路径?

[英]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.

相关问题 在 Spring Boot 中无法通过 Neo4j 实现 CRUD 操作 - Cannot implement CRUD operations through Neo4j in Spring Boot 如何在Spring Boot / Data Neo4j中使用Bolt驱动程序 - How can I use the Bolt driver with Spring Boot/Data Neo4j 我如何获得Neo4j的路径 <config storeDirectory=“”> 在批处理插入器方法? - How can I get the path of my Neo4j <config storeDirectory=“”> in a Batch Inserter method? 如何使用 boot 2.0 和 Neo4j SDN5 在 spring 单元测试中配置我自己的 GraphDatabaseService 和 GraphAwareRuntime - How to I configure my own GraphDatabaseService and GraphAwareRuntime in a spring unit test with boot 2.0 and Neo4j SDN5 如何使用 spring 引导在 java 中运行 neo4j 查询? - how to use spring boot to run neo4j queries in java? 如何通过java代码从Neo4j获取节点 - How to get nodes from Neo4j through java code Neo4j 3.1遍历API,如何找到两个节点之间的最短路径? - Neo4j 3.1 traversal API, how to find shortest Path between two nodes? 如何计算与 neo4j 的共同好友? - How to calculate mutual friends with neo4j? spring neo4j:如何按不区分大小写的索引字段搜索数据? - spring neo4j: how can I search data by index field case insensitive? 如何在Spring数据neo4j中更新节点或节点实体? - How can I update node or node entity in Spring data neo4j?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM