在我的项目中,我使用Spring 3和Neo4j 2.0.1,我使用的是嵌入式模式,一切正常。 在我的代码中,我使用了Neo4jTemplate(我的服务中的@Autowired)以及GraphRepository和RelationshipOperationsRepository。
我想迁移我的coode以使用独立模式。这是我做的:
<!-- Neo4J -->
<!-- neo4j:config storeDirectory="${neo.storeDir}" base-package="net.nextep.nextenergy.domain.graph" /-->
<bean id="graphDatabase" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
<constructor-arg value="http://localhost:7474/db/data/" index="0"/>
</bean>
<neo4j:repositories base-package="net.nextep.nextenergy.repository.graph" />
我试图运行它,我收到了这个错误:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'neo4jTemplate' is defined
然后我尝试从我的服务中移除@Autowired Neo4jTemplate
,使用@Autowired private SpringRestGraphDatabase graphDB
并以这种方式创建新模板private Neo4jTemplate template = new Neo4jTemplate((GraphDatabase) graphDB)
我仍然得到同样的错误:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userNodeRepository': Cannot resolve reference to bean 'neo4jTemplate' while setting bean property 'neo4jTemplate'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'neo4jTemplate' is defined
...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'neo4jTemplate' is defined
...
UserNodeRepository :
@Repository
public interface UserNodeRepository extends GraphRepository<UserNode>,
RelationshipOperationsRepository<UserNode>{
public UserNode findById(String id);
public Node findNodeById(String id);
@Query("match (u:UserNode)-[:HABILITATED]->(f:Folder) where ID(u) = {0} return f")
public Set<Folder> getAllowedFoldersFirstLevel(UserNode user);
}
我做错了吗?
答案 0 :(得分:1)
将bean命名为“graphDatabaseService”并将其传递给您未创建的配置:
<neo4j:config graphDatabaseService="graphDatabaseService" base-package="net.nextep.nextenergy.domain.graph" />
<bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
<constructor-arg value="http://localhost:7474/db/data/" index="0"/>
</bean>
<neo4j:repositories base-package="net.nextep.nextenergy.repository.graph" />