【问题标题】:SDN with Neo4j 2.2xSDN 与 Neo4j 2.2x
【发布时间】:2015-10-09 04:41:13
【问题描述】:

许多人声称 SDN 版本 3.3.1 或 4.0.0.RC1 应该可以与 neo4j 2.2.x 一起使用,但我无法使其正常工作。

我有这个 spring 配置配置:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.2.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <context:annotation-config />
    <context:spring-configured />

    <neo4j:config graphDatabaseService="graphDatabaseService" base-package="com.x.protogy.neo4j"/>
    <bean id="graphDatabaseService"
        class="org.springframework.data.neo4j.rest.SpringCypherRestGraphDatabase">
      <constructor-arg index="0" value="http://localhost:7476/db/data" />
    </bean>
    <tx:annotation-driven mode="aspectj"
        transaction-manager="transactionManager" />

</beans>

这会产生这个异常:

Caused by: java.lang.ClassNotFoundException: org.neo4j.kernel.impl.nioneo.store.StoreId
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1324)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1177)

看代码就明白了:SDN指的是neo4j库中的一个类,在2.2.x中被淘汰了:

org.neo4j.kernel.impl.nioneo.store.StoreId

在这种情况下我有什么选择?

【问题讨论】:

    标签: spring-data-neo4j


    【解决方案1】:

    试试这个 Java 配置文件而不是 XML 配置。

    import org.neo4j.ogm.session.Session;
    import org.neo4j.ogm.session.SessionFactory;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.ComponentScan;
    
    
    @Configuration
    @EnableNeo4jRepositories("com.app.repository")
    @EnableTransactionManagement
    @ComponentScan("com.app")
    
    public class AppNeo4jConfiguration extends Neo4jConfiguration{
    
    
        public SessionFactory getSessionFactory() {
            return new SessionFactory("com.app.bo");
        }
    
    
        @Bean
        public Neo4jServer neo4jServer() {
            return new RemoteServer("http://localhost:7474");
        }
    
    
        @Bean
        @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
        public Session getSession() throws Exception {
            return super.getSession();
        }
    }
    

    【讨论】:

      【解决方案2】:

      我可以专门为 SDN 4 (4.0.0.RC1) 回答 - 它绝对适用于 Neo4j 2.2

      不支持 XML 配置,因此您需要使用基于 Java 的配置。见http://docs.spring.io/spring-data/neo4j/docs/4.0.0.RC1/reference/html/#reference_setup

      还有一个简短的指南https://www.airpair.com/neo4j/posts/the-essence-of-spring-data-neo4j-4

      和示例应用程序https://github.com/neo4j-examples?query=sdn4

      【讨论】:

        【解决方案3】:

        在让 SDN 与新的 Neo4j 一起工作时,我也遇到了一些问题: Cannot configure @Transaction to work with Spring Data Neo4j

        (顺便说一句。有一个对我有用的 Java 配置,也许在从 XML 迁移到 Java 时尝试一下......)

        这也可能是由于neo4j-kernel jar中缺少类引起的...在调试和调查源代码后设法找到解决方法,但目前最好的办法可能是降级neo4j版本...

        【讨论】:

        • 接近但我没有使用嵌入式服务器,而是使用其他端点服务器。我认为要么我仍然缺少某些东西,要么新的 SDN 只有在嵌入服务器时才能工作。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-24
        • 1970-01-01
        相关资源
        最近更新 更多