将Neo4J与SpringBoot连接

时间:2017-04-24 19:50:07

标签: spring-boot spring-data-neo4j

我需要帮助将neo4j数据库连接到spring boot。我一整天都在谷歌上搜索,但却无法搞清楚。我可以创建一个spring boot应用程序,创建一个调用Service的REST控制器,然后创建用于SQl的Spring数据JPA存储库,但不能为图形数据库执行此操作,任何人都可以帮我配置Graph数据库以进行Spring启动。 我是Neo4j的新手,已被分配任务。

谢谢你。 我添加了任何教程告诉我的内容:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.3.RELEASE</version>
</parent>
<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>4.2.3.RELEASE</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-neo4j-rest -->
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j-rest</artifactId>
        <version>3.4.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-configuration</artifactId>
        <version>3.2.0-alpha08</version>
    </dependency>


</dependencies>
<properties>
    <start-class>com.sumit.demo.AppBootConfig</start-class>
    <java.version>1.8</java.version>
</properties>
<build>
    <finalName>people</finalName>
</build>

我的主要是:

@SpringBootApplication(exclude = { Neo4jDataAutoConfiguration.class })
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class })
public class AppBootConfig extends SpringBootServletInitializer {
public static void main(String[] args) {
    SpringApplication.run(AppBootConfig.class, args);
     }
}

我尝试配置但得到了这个:

017-04-25 01:10:03.316  WARN 5772 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [com.sumit.demo.AppBootConfig]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/data/neo4j/config/Neo4jConfiguration.class] cannot be opened because it does not exist

2017-04-25 01:10:03.323 ERROR 5772 --- [main] o.s.b.f.s.DefaultListableBeanFactory:在bean上销毁名为&#39; org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory&#39;抛出异常

java.lang.IllegalStateException:ApplicationEventMulticaster未初始化 - 调用&#39;刷新&#39;在通过上下文组播事件之前:org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2f9f7dcf:启动日期[Tue Apr 25 01:10:02 IST 2017];上下文层次结构的根     在org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:404)[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253)〜[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:959)[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:966)[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1033)[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:555)[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]     在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]     在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]     在org.springframework.boot.SpringApplication.run(SpringApplication.java:315)[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]     在org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]     在org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]     在com.sumit.demo.AppBootConfig.main(AppBootConfig.java:15)[classes /:na]

2017-04-25 01:10:03.334 ERROR 5772 --- [main] o.s.boot.SpringApplication:应用程序启动失败

org.springframework.beans.factory.BeanDefinitionStoreException:无法处理配置类[com.sumit.demo.AppBootConfig]的导入候选项;嵌套异常是java.io.FileNotFoundException:类路径资源[org / springframework / data / neo4j / config / Neo4jConfiguration.class]无法打开,因为它不存在     在org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:541)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:475)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:184)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:270)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)〜[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]     在org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]     在org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]     在org.springframework.boot.SpringApplication.run(SpringApplication.java:315)[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]     在org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]     在org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]     在com.sumit.demo.AppBootConfig.main(AppBootConfig.java:15)[classes /:na] 引起:java.io.FileNotFoundException:类路径资源[org / springframework / data / neo4j / config / Neo4jConfiguration.class]无法打开,因为它不存在     在org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)〜[spring-core-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.core.type.classreading.SimpleMetadataReader。(SimpleMetadataReader.java:50)〜[spring-core-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:98)〜[spring-core-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.createMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:89)〜[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]     at org.springframework.boot.type.classreading.ConcurrentReferenceCachingMetadataReaderFactory.getMetadataReader(ConcurrentReferenceCachingMetadataReaderFactory.java:76)〜[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]     在org.springframework.core.type.classreading.SimpleMetadataReaderFactory.getMetadataReader(SimpleMetadataReaderFactory.java:93)〜[spring-core-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:633)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.annotation.ConfigurationClassParser $ SourceClass.getSuperClass(ConfigurationClassParser.java:797)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:308)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:230)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.annotation.ConfigurationClassParser.processMemberClasses(ConfigurationClassParser.java:329)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:247)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:230)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     在org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:532)〜[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]     ...省略了15个常见帧

2 个答案:

答案 0 :(得分:0)

首先,你的pom非常凌乱。仅添加所需的依赖项。你只需要这个

   <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>4.1.5.RELEASE</version>
    </dependency>  
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j-rest</artifactId>
        <version>3.4.6.RELEASE</version>
</dependency>

你的主要课程应该有这样的东西

@SpringBootApplication
@EnableNeo4jRepositories("com.in.neo4j.repository.neo")  

我不确定你为什么要排除一些自动配置

答案 1 :(得分:0)

您提供的引用不包含 Application.properties

因此,这是 Application.properties 文件,用于连接到Neo4j。

spring.data.neo4j.uri=bolt://localhost
spring.data.neo4j.username=neo4j
spring.data.neo4j.password=Your_Password

作为控制台应用程序启动Neo4j数据库,该应用程序最有可能在localhost:7474端口上运行。

启动命令:

neo4j console

还要检查依赖性。由于最新版本仅适用于

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>