minglight
minglight

Reputation: 87

How to get Neo4jTemplate in SDN4

I am using Spring Data Neo4j 4(SDN4) from the example project SDN4-northwind(https://github.com/amorgner/sdn4-northwind),when I try to get the Neo4jTemplate bean,I get the error message like this. Does anyone know how to get the Neo4jTemplate bean from SDN4?

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)

Here is the Configuration file

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();
}

}

Upvotes: 2

Views: 2029

Answers (1)

Luanne
Luanne

Reputation: 19373

Assdd

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

to AppContext and then @Autowired Neo4jOperations neo4jTemplate;

Upvotes: 5

Related Questions