Neo4J 连接池在应用程序启动后关闭

Neo4J connection pool is closing after application starts

我是 运行 我的应用程序和 Docker 组合环境中的 Neo4j 4。启动我的应用程序后,我收到一些奇怪的日志,连接池正在关闭与数据库的连接 (Closing connection pool towards graphdb(172.21.0.4):7687),此后 neo4jClient 无法查询数据库(下面的日志)。这种行为的原因是什么?

顺便说一句。我创建了 Spring 健康检查 (driver.verifyConnectivity()),但它总是 return OK(没有抛出错误)。

有什么想法吗?


@Configuration
class Neo4jConfiguration {
    private val logger = LoggerFactory.getLogger(Neo4jConfiguration::class.java)

    @Bean
    fun neo4jDriver(
            @Value("${spring.data.neo4j.host}") host: String?,
            @Value("${spring.data.neo4j.port}") port: Int?): Driver {
        val connectionUrl = "neo4j://$host:$port"
        logger.info("Connecting to Neo4j on `$connectionUrl`")
        return GraphDatabase.driver(connectionUrl/*, AuthTokens.basic("neo4j", "secret")*/) 
    }

    @Bean
    fun neo4jClient(): ReactiveNeo4jClient = ReactiveNeo4jClient.create(neo4jDriver(null, null))

    @Bean
    fun neo4jTransactionManager() = ReactiveNeo4jTransactionManager(neo4jDriver(null, null))
}

Docker撰写:

version: '3.7'
services:
  graphdb:
    image: neo4j:4.0.0
    ports:
      - 7474:7474
      - 7687:7687
    environment:
      NEO4J_AUTH: none
      NEO4J_dbms_connectors_default__listen__address: 0.0.0.0
    volumes:
      - ./docker/neo4j/data:/data
    networks:
      - things
networks:
  things:
    name: things

完整日志:

2020-02-24 20:57:32.922  INFO 1 --- [  restartedMain] c.t.r.repo.neo4j.Neo4jConfiguration      : Connecting to Neo4j on `neo4j://graphdb:7687`
2020-02-24 20:57:33.321  INFO 1 --- [  restartedMain] Driver                                   : Routing driver instance 656417291 created for server address graphdb:7687
2020-02-24 20:57:43.329  INFO 1 --- [o4jDriverIO-2-3] LoadBalancer                             : Routing table for database 'system' is stale. Ttl 1582577863326, currentTime 1582577863328, routers AddressSet=[], writers AddressSet=[], readers AddressSet=[], database 'system'
2020-02-24 20:57:43.437  INFO 1 --- [o4jDriverIO-2-2] ConnectionPool                           : Closing connection pool towards graphdb(172.21.0.4):7687, it has no active connections and is not in the routing table registry.
2020-02-24 20:57:43.440  INFO 1 --- [o4jDriverIO-2-2] LoadBalancer                             : Updated routing table for database 'system'. Ttl 1582578163422, currentTime 1582577863439, routers AddressSet=[0.0.0.0:7687], writers AddressSet=[0.0.0.0:7687], readers AddressSet=[0.0.0.0:7687], database 'system'
2020-02-24 20:58:02.694  INFO 1 --- [ault-executor-1] LoadBalancer                             : Routing table for database '<default database>' is stale. Ttl 1582577882693, currentTime 1582577882694, routers AddressSet=[], writers AddressSet=[], readers AddressSet=[], database '<default database>'
2020-02-24 20:58:02.777  INFO 1 --- [o4jDriverIO-2-2] ConnectionPool                           : Closing connection pool towards graphdb(172.21.0.4):7687, it has no active connections and is not in the routing table registry.
2020-02-24 20:58:02.777  INFO 1 --- [o4jDriverIO-2-2] LoadBalancer                             : Updated routing table for database '<default database>'. Ttl 1582578182776, currentTime 1582577882777, routers AddressSet=[0.0.0.0:7687], writers AddressSet=[0.0.0.0:7687], readers AddressSet=[0.0.0.0:7687], database '<default database>'
2020-02-24 20:58:02.803  WARN 1 --- [o4jDriverIO-2-2] LoadBalancer                             : Failed to obtain a connection towards address 0.0.0.0:7687

org.neo4j.driver.exceptions.SessionExpiredException: Server at 0.0.0.0:7687 is no longer available
    at org.neo4j.driver.internal.cluster.loadbalancing.LoadBalancer.lambda$acquire(LoadBalancer.java:204) ~[neo4j-java-driver-4.0.0.jar:4.0.0-d03d93ede8ad65657eeb90ed890757203ecfaa7a]
    at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(Unknown Source) ~[na:na]
    at java.base/java.util.concurrent.CompletableFuture.uniWhenCompleteStage(Unknown Source) ~[na:na]
  [... removed ...]
Caused by: org.neo4j.driver.exceptions.ServiceUnavailableException: Unable to connect to 0.0.0.0:7687, ensure the database is running and that there is a working network connection to it.
    at org.neo4j.driver.internal.async.connection.ChannelConnectedListener.databaseUnavailableError(ChannelConnectedListener.java:76) ~[neo4j-java-driver-4.0.0.jar:4.0.0-d03d93ede8ad65657eeb90ed890757203ecfaa7a]
    at org.neo4j.driver.internal.async.connection.ChannelConnectedListener.operationComplete(ChannelConnectedListener.java:70) ~[neo4j-java-driver-4.0.0.jar:4.0.0-d03d93ede8ad65657eeb90ed890757203ecfaa7a]
    at org.neo4j.driver.internal.async.connection.ChannelConnectedListener.operationComplete(ChannelConnectedListener.java:37) ~[neo4j-java-driver-4.0.0.jar:4.0.0-d03d93ede8ad65657eeb90ed890757203ecfaa7a]
  [... removed ...]
    ... 7 common frames omitted
Caused by: org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: /0.0.0.0:7687
Caused by: java.net.ConnectException: Connection refused
    at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:na]
    at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source) ~[na:na]
    [... removed ...]

我刚遇到同样的问题,经过一些试验发现ip应该是"bolt://$host:$port"而不是"neo4j://$host:$port"

似乎某些 spring.io 教程已过时。