spring - 如何在SDN4中获取Neo4jTemplate

标签 spring spring-data spring-data-neo4j-4

我正在使用示例项目 SDN4-northwind( https://github.com/amorgner/sdn4-northwind ) 中的 Spring Data Neo4j 4(SDN4),当我尝试获取 Neo4jTemplate bean 时,我收到如下错误消息。 有谁知道如何从SDN4获取Neo4jTemplate bean?

Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.data.neo4j.template.Neo4jTemplate] is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:371)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:331)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:968)
at org.neo4j.example.northwind.Run.main(Run.java:34)

这是配置文件

package org.neo4j.example.northwind;

import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.config.Neo4jConfiguration;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.server.Neo4jServer;
import org.springframework.data.neo4j.server.RemoteServer;
import org.springframework.transaction.annotation.EnableTransactionManagement;


@Configuration
@EnableNeo4jRepositories("org.neo4j.example.northwind.repository")
@EnableTransactionManagement
public class AppContext extends Neo4jConfiguration {

public static final String NEO4J_HOST = "http://localhost:";
public static final int    NEO4J_PORT = 7474;

@Override
public SessionFactory getSessionFactory() {
    System.setProperty("username", "neo4j");
    System.setProperty("password", System.getProperty("password","osp"));
    return new SessionFactory("org.neo4j.example.northwind.model");
}

@Bean
@Override
public Neo4jServer neo4jServer() {
    return new RemoteServer(NEO4J_HOST + NEO4J_PORT);
}

@Bean
@Override
//@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public Session getSession() throws Exception {
    return super.getSession();
}

}

最佳答案

Assdd

@Bean
 public Neo4jOperations getNeo4jTemplate() throws Exception {
     return new Neo4jTemplate(getSession());
 }

AppContext,然后@Autowired Neo4jOperations neo4jTemplate;

关于spring - 如何在SDN4中获取Neo4jTemplate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31778915/

相关文章:

java - Spring boot : Managing bean scope "manually" for dynamically creating beans at runtime with differing states. 我们的解决方案有问题吗?

java - 如何在运行时更改属性文件并刷新配置类?

Spring 数据 mongodb 存储库。如何通过 ID 列表进行搜索?

java - 将 Spring Mongo 更新转换为 JSON 字符串

spring - 将 Neo4j Server 与 Spring Data Neo4j 远程使用时不保存数据

java - Spring XML 发送 :advice equivalent of @TransactionConfiguration?

spring - 奇怪的异常 : "Name must not be null or empty!"

java - Spring 数据按顺序获取映射对象

java - Spring Data Neo4j 未将类字段映射到节点属性

java - SDN 4-RC1 : RelationRepository. save(relationshipEntity) 不在图形中保存关系实体