无法使用spring-data-neo4j 2.2.1加载Neo4jConfiguration

时间:2013-06-10 15:48:36

标签: neo4j spring-data-neo4j

我是Neo4j和Spring的新手。我尽力做好我的家庭作业 - 如果有一个神奇的医生,我会尽心尽力地回答我所遗漏的所有答案。

目的是使用spring-data-neo4j与Neo4j数据库进行交互。我已经按照Good Relationships中的指南取得了一些成功,但是希望继续使用本书中使用的1.6.M02版本。

虽然在Spring-data-neo4j 2.2.1的Maven资源库中不是specified,但是Maven包含的Neo4j版本是1.8.1,据我所知是正确的版。这也应该引入Spring框架(3.1.4)。所以pom.xml看起来像是:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>yet</groupId>
    <artifactId>another</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>cinecopy</name>

    <dependencies>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-neo4j</artifactId>
            <version>2.2.1.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>3.1.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib-nodep</artifactId>
            <version>3.0</version>
        </dependency>


    </dependencies>
</project>

那么我们就有了最简单的测试用例:

@ContextConfiguration(locations = "classpath:testContext.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class SomeTest {

    @Autowired
    Neo4jTemplate template;

    @Test
    @Transactional
    public void badNews() {

        Person add = new Person();
        add.setName("What.");

        add = template.save(add);

    }

}

其中涉及testContext.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<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"
        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.0.xsd">

    <context:annotation-config/>
    <neo4j:config storeDirectory="target/config-test"/>

</beans>

这给了我(full trace):

Failed to load ApplicationContext [...]
Cannot load configuration class: org.springframework.data.neo4j.config.Neo4jConfiguration

我发现这一点很特殊,因为事情似乎与pom.xml一样正常:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>yet</groupId>
    <artifactId>another</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>cinecopy</name>

    <dependencies>
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j</artifactId>
            <version>1.6.M02</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-neo4j</artifactId>
            <version>2.0.0.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
    </dependencies> 
</project>

非常感谢任何指导!

1 个答案:

答案 0 :(得分:1)

作为参考,迈克尔输入之后pom.xml(或this question - 声称做完我的作业太多了):

<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
        http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <groupId>another</groupId>
    <artifactId>cine</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>yetagain</name>

    <dependencies>
        <dependency>
            <groupId>org.neo4j</groupId>
            <artifactId>neo4j</artifactId>
            <version>1.9</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-neo4j</artifactId>
            <version>2.3.0.M1</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>

        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.geronimo.specs</groupId>
            <artifactId>geronimo-validation_1.0_spec</artifactId>
            <version>1.1</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.7.3</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>3.1.4.RELEASE</version>
        </dependency>

    </dependencies>
</project>
然而,我没有遇到与史蒂夫相同的“悬挂”问题 - 但到目前为止,我所做的只是加载ApplicationContext。