项目启动时如何使Spring Data Neo4j忽略连接检查?

问题描述 投票:0回答:2

我在SpringBoot项目中使用Spring-Data-Neo4j。但是,当neo4j控制台未在后面运行时,IntelliJ Idea总是给出以下错误消息:

Caused by: org.neo4j.driver.v1.exceptions.ServiceUnavailableException: Unable to connect to localhost:7687, ensure the database is running and that there is a working network connection to it.

我知道错误的原因。原因我没有启动数据库。数据库未运行时如何避免发生错误。

下面是我的代码:

Main Class

@SpringBootApplication
@EntityScan(basePackages = "com.inspur.neo4j.domain")
@EnableNeo4jRepositories("com.inspur.neo4j.repositories")
public class DataGraphApplication {
    public static void main(String[] args) {

        SpringApplication.run(DataGraphApplication.class, args);
    }
}

application.yml

server:
  port: 9012
spring:
  data:
    neo4j:
      uri: bolt://localhost
      username: neo4j
      password: Passw0rd

没有任何方法可以避免在数据库未运行时发生错误?

对不起我的英语。

neo4j spring-data-neo4j
2个回答
0
投票

是,您可以禁用此功能将此添加到您的主类

@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class})

0
投票

幸运的是,我在官方website上找到了答案。我们可以将以下属性添加到springboot application.yml文件。

management.health.neo4j.enabled 

完整的配置如下:

server:
  port: 9012
spring:
  data:
    neo4j:
      uri: bolt://localhost
      username: neo4j
      password: Passw0rd
management:
    neo4j:
      enabled: false

最后,当neo4j控制台未在后面运行时,IntelliJ Idea从不显示错误消息。

© www.soinside.com 2019 - 2024. All rights reserved.