我正在尝试将我们项目的'spring-data-neo4j'依赖项从2-1-0-M1版本(使用neo4j 1.6)升级到2.2.0.RELEASE(使用neo4j 1.8.1)版本。但是,当我更改spring-data-neo4j依赖项的版本时,甚至更改为2.1.0.RELEASE,在Tomcat上启动应用程序时出现以下异常:
[ERROR] [host-startStop-1] [org.springframework.web.context.ContextLoader:307] - Context initialization failed
org.springframework.data.neo4j.mapping.InvalidEntityTypeException: Type class java.lang.RuntimeException is neither a @NodeEntity nor a @RelationshipEntity
at org.springframework.data.neo4j.support.mapping.Neo4jMappingContext.createPersistentEntity(Neo4jMappingContext.java:56)
at org.springframework.data.neo4j.support.mapping.Neo4jMappingContext.createPersistentEntity(Neo4jMappingContext.java:46)
at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:269)
at org.springframework.data.neo4j.support.mapping.Neo4jMappingContext.addPersistentEntity(Neo4jMappingContext.java:61)
at org.springframework.data.neo4j.support.mapping.Neo4jMappingContext.addPersistentEntity(Neo4jMappingContext.java:46)
at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:246)
at org.springframework.data.mapping.context.AbstractMappingContext.initialize(AbstractMappingContext.java:346)
at org.springframework.data.mapping.context.AbstractMappingContext.onApplicationEvent(AbstractMappingContext.java:336)
at org.springframework.data.mapping.context.AbstractMappingContext.onApplicationEvent(AbstractMappingContext.java:69)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:97)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:324)
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:929)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:467)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:384)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4887)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5381)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1655)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
我也尝试过'升级''spring-data-neo4j'库(并让v1.6上的neo4j)并得到了例外。因此异常似乎只与spring-data-neo4j库有关,而与neo4j本身无关。
之前有没有人见过这种行为,或者有任何线索为什么Spring-data-neo4j认为RuntimeException应该是NodeEntity还是RelationshipEntity?
不幸的是,代码分布在多个项目中,这使得在此处粘贴导致问题的最小配置变得困难。仍在努力。已经通过删除所有注释和内容来“清理”所有neo4j实体(和关系)类和DAO,以确保它与它们中的任何一个都无关。但是,当启动应用程序时,会出现异常。
编辑:下面是使用的弹簧配置:
<?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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/data/neo4j
http://www.springframework.org/schema/data/neo4j/spring-neo4j-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config />
<context:component-scan base-package="nl.graph" />
<tx:annotation-driven mode="proxy"/>
<bean id="graphDb" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/neo4j/graphDb" />
</bean>
<bean id="graphDatabaseService" class="org.neo4j.kernel.EmbeddedGraphDatabase"
destroy-method="shutdown">
<constructor-arg index="0" ref="graphDb" />
</bean>
<neo4j:config graphDatabaseService="graphDatabaseService" />
<neo4j:repositories base-package="nl.graph.repositories" />
<bean id="neo4jTransactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManager">
<bean class="org.neo4j.kernel.impl.transaction.SpringTransactionManager">
<constructor-arg index="0" ref="graphDatabaseService" />
</bean>
</property>
<property name="userTransaction">
<bean class="org.neo4j.kernel.impl.transaction.UserTransactionImpl">
<constructor-arg index="0" ref="graphDatabaseService" />
</bean>
</property>
</bean>
</beans>
编辑21-05:找到原因,在某些应用程序上下文中定义了以下bean:
<bean id="runtimeException" class="java.lang.Class" factory-method="forName">
<constructor-arg value="java.lang.RuntimeException"/>
</bean>
删除此bean(为spring-batch的FaultTolerantStepFactoryBean的skippableExceptionClasses属性定义)解决了这个问题。不知怎的,这个bean是通过neo4j组件扫描找到的?