我正在尝试将我们项目的“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 属性定义的)解决了这个问题。不知何故,neo4j 组件扫描发现了这个 bean?