2014-03-27 44 views
2

我正在構建Spring數據和嵌入Neo4j的POC,我遵循Spring數據文檔的配置教程,但是當我嘗試運行該項目時,出現「創建錯誤在ServletContext資源中定義名爲'graphDatabaseService'的bean。配置Spring數據和嵌入neo4j的錯誤

我在我的applicationContext.xml和一些不同版本的Spring Data和Neo4j依賴項上嘗試了一些不同的配置,但都沒有成功,只是出現了不同的錯誤。哪裏不對?

這裏是我的applicationContext.xml中,pom.xml中和堆棧跟蹤:

的applicationContext.xml

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

    <context:annotation-config /> 

    <bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase" 
     destroy-method="shutdown"> 
     <constructor-arg index="0" value="data/graph.db" /> 
     <constructor-arg index="1"> 
      <map> 
       <entry key="enable_remote_shell" value="true" /> 
      </map> 
     </constructor-arg> 
    </bean> 

    <bean id="serverWrapper" class="org.neo4j.server.WrappingNeoServerBootstrapper" 
     init-method="start" destroy-method="stop"> 
     <constructor-arg ref="graphDatabaseService" /> 
    </bean> 



    <context:component-scan base-package="br.com.teste" /> 

</beans> 

的pom.xml

<properties> 
    <spring.version>4.0.2.RELEASE</spring.version> 
    </properties> 

    <dependencies> 

    <dependency> 
     <groupId>javax.persistence</groupId> 
     <artifactId>persistence-api</artifactId> 
     <version>1.0</version> 
     <optional>true</optional> 
    </dependency> 
    <dependency> 
     <groupId>org.testng</groupId> 
     <artifactId>testng</artifactId> 
     <version>6.1.1</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>cglib</groupId> 
     <artifactId>cglib</artifactId> 
     <version>2.2.2</version> 
    </dependency> 

    <!-- Spring 3 dependencies --> 
    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-core</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-web</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-webmvc</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-context</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 

    <dependency> 
     <groupId>org.springframework</groupId> 
     <artifactId>spring-test</artifactId> 
     <version>${spring.version}</version> 
    </dependency> 


    <!-- Spring Data Neo4j --> 
    <dependency> 
     <groupId>org.springframework.data</groupId> 
     <artifactId>spring-data-neo4j</artifactId> 
     <version>3.0.1.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.neo4j</groupId> 
     <artifactId>neo4j</artifactId> 
     <version>2.1.0-M01</version> 
    </dependency> 

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

    <dependency> 
     <groupId>org.aspectj</groupId> 
     <artifactId>aspectjrt</artifactId> 
     <version>1.7.4</version> 
    </dependency> 
    <dependency> 
     <groupId>org.neo4j.app</groupId> 
     <artifactId>neo4j-server</artifactId> 
     <classifier>static-web</classifier> 
     <version>2.1.0-M01</version> 
    </dependency> 



    <!-- Apache Commons Lang --> 
    <dependency> 
     <groupId>commons-lang</groupId> 
     <artifactId>commons-lang</artifactId> 
     <version>2.4</version> 
    </dependency> 


    <!-- JSON Resolver --> 
    <dependency> 
     <groupId> org.codehaus.jackson</groupId> 
     <artifactId>jackson-mapper-asl</artifactId> 
     <version>1.9.12</version> 
    </dependency> 

    <!-- JSTL --> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>jstl</artifactId> 
     <version>1.2</version> 
    </dependency> 
    <dependency> 
     <groupId>javax.servlet</groupId> 
     <artifactId>servlet-api</artifactId> 
     <version>2.5</version> 
    </dependency> 

    <dependency> 
     <groupId>javax.validation</groupId> 
     <artifactId>validation-api</artifactId> 
     <version>1.0.0.GA</version> 
    </dependency> 
    </dependencies> 

    <repositories> 
     <repository> 
      <id>neo4j-release-repository</id> 
      <name>Neo4j Maven 2 release repository</name> 
      <url>http://m2.neo4j.org/content/repositories/releases/</url> 
      <releases> 
       <enabled>true</enabled> 
      </releases> 
      <snapshots> 
       <enabled>false</enabled> 
      </snapshots> 
    </repository> 
    <repository> 
     <id>spring-maven-milestone</id> 
     <name>Springframework Maven Repository</name> 
     <url>http://maven.springframework.org/milestone</url> 
    </repository> 
</repositories> 

<build> 
    <finalName>teste-spring</finalName> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.2</version> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
     </plugin> 


     <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>aspectj-maven-plugin</artifactId> 
     <version>1.2</version> 
     <dependencies> 
      <!-- NB: You must use Maven 2.0.9 or above or these are ignored (see MNG-2972) --> 
      <dependency> 
       <groupId>org.aspectj</groupId> 
       <artifactId>aspectjrt</artifactId> 
       <version>1.7.4</version> 
      </dependency> 
      <dependency> 
       <groupId>org.aspectj</groupId> 
       <artifactId>aspectjtools</artifactId> 
       <version>1.7.4</version> 
      </dependency> 
     </dependencies> 
     <executions> 
      <execution> 
       <goals> 
        <goal>compile</goal> 
        <goal>test-compile</goal> 
       </goals> 
      </execution> 
     </executions> 
     <configuration> 
      <outxml>true</outxml> 
      <aspectLibraries> 
       <aspectLibrary> 
        <groupId>org.springframework</groupId> 
        <artifactId>spring-aspects</artifactId> 
       </aspectLibrary> 
       <aspectLibrary> 
        <groupId>org.springframework.data</groupId> 
        <artifactId>spring-data-neo4j-aspects</artifactId> 
       </aspectLibrary> 
      </aspectLibraries> 
      <source>1.7</source> 
      <target>1.7</target> 
     </configuration> 
    </plugin> 
    </plugins>  
    </build> 
</project> 

堆棧跟蹤

Mar 26, 2014 11:39:29 PM org.apache.catalina.core.StandardContext listenerStart 
Grave: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphDatabaseService' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.neo4j.kernel.configuration.Config]: Could not convert constructor argument value of type [java.lang.String] to required type [org.neo4j.kernel.configuration.Config]: Failed to convert value of type 'java.lang.String' to required type 'org.neo4j.kernel.configuration.Config'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.neo4j.kernel.configuration.Config]: no matching editors or conversion strategy found 
Related cause: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphDatabaseService' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Unsatisfied dependency expressed through constructor argument with index 2 of type [java.lang.Iterable]: Ambiguous constructor argument types - did you specify the correct bean references as constructor arguments? 
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:716) 
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:185) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4961) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5455) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:744) 
Related cause: 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'graphDatabaseService' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Unsatisfied dependency expressed through constructor argument with index 2 of type [java.lang.Iterable]: Ambiguous constructor argument types - did you specify the correct bean references as constructor arguments? 
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:727) 
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:185) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1114) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1017) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4961) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5455) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:744) 
+0

是否有最新的Neo4j穩定版本(2.0.1)的工作?他們似乎在里程碑版本中添加了第二個構造函數,因此可能會導致模糊。 – tstorms

+0

不,我試過Neo4j 2.0.1和Spring Data的實際(3.0.1)和以前的版本(2.3.5)的里程碑 –

回答

2

如同EmbeddedGraphDatabase類已棄用(它將隱藏在將來的版本中),已經避免它是一種很好的做法。建立GraphDatabaseSerice的最佳方法是使用GraphDatabaseFactory並在您的情況下使用相關的GraphDatabaseBuilder。如果您想配置您的Java Spring bean的,這是它可能是什麼樣子:

@Configuration 
@ImportResource("applicationContext.xml") 
class SpringConfiguration extends Neo4jConfiguration { 
    @Bean(destroyMethod = "shutdown") 
    public GraphDatabaseService graphDatabaseService() { 
     return new GraphDatabaseFactory().newEmbeddedDatabaseBuilder("db") 
      .setConfig("enable_remote_shell", "true").newGraphDatabase(); 
    } 
} 

我意識到setConfig方法我使用的是過時的好,但我不認爲在同等類GraphDatabaseSettings

如果你想使用這種方法,你必須在你的web.xml中使用AnnotationConfigWebApplicationContext

如果您希望繼續使用XML配置,有」便利豆:

<bean id="graphDatabaseService" class="org.springframework.data.neo4j.support.GraphDatabaseServiceFactoryBean" 
     destroy-method="shutdown" scope="singleton"> 
    <constructor-arg value="db"/> 
    <constructor-arg> 
     <map> 
      <entry key="enable_remote_shell" value="true"/> 
     </map> 
    </constructor-arg> 
</bean> 
+0

我看過這個博客文章,並試過這個例子,但後來我得到了一個不同的錯誤:「無法獲取鎖定存儲鎖定文件:data/graph.db/store_lock。請確保沒有其他進程正在使用此數據庫,並且該目錄是可寫的(即使對於只讀訪問也是必需的)」,至極沒有意義,數據庫目錄是在運行時創建的,因此沒有其他進程正在使用它,並且完全有權寫入目錄及其文件。 –

+0

也請參閱更新後的文章。你得到的異常可能與'WrappingNeoServerBootstrapper'有關。它指的是同一個'graphDatabaseService'嗎? – tstorms

+0

另外,使用'WrappingNeoServer'類,而不是'WrappingNeoServerBootstrapper'。 – tstorms

相關問題