Hi,

I'm new to Neo4j (and Spring). I am following this spring data neo4j 
tutorial <http://spring.io/guides/gs/accessing-data-neo4j/> and am stuck on 
how to proceed. Since the EmbeddedGraphDatabase has been deprecated I 
decided to change the code to use the recommended GraphDatabaseService API. 
However, I keep getting a runtime error as below. All my code is the same 
as the tutorial (i.e.Person.java, PersonRepository.java) except for where I 
have changed it to use GraphDatabaseService. Please can someone help me.

Runtime Error Message:
-----------------------------------
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.0.2.RELEASE)

2014-05-26 23:49:37.840  INFO 698 --- [           main] 
com.me.nosql.neo4j.hello.Application     : Starting Application on 
mes-iMac.local with PID 698 
(/Users/me/IdeaProjects/Neo4j-Example/target/classes started by me in 
/Users/me/IdeaProjects/Neo4j-Example)
2014-05-26 23:49:37.896  INFO 698 --- [           main] 
s.c.a.AnnotationConfigApplicationContext : Refreshing 
org.springframework.context.annotation.AnnotationConfigApplicationContext@647d5718:
 
startup date [Mon May 26 23:49:37 BST 2014]; root of context hierarchy
2014-05-26 23:49:38.682  WARN 698 --- [           main] 
f.a.AutowiredAnnotationBeanPostProcessor : Autowired annotation should be 
used on methods with actual parameters: public 
org.springframework.data.neo4j.core.GraphDatabase 
org.springframework.data.neo4j.config.Neo4jConfiguration.graphDatabase()

Error starting ApplicationContext. To display the auto-configuration report 
enabled debug logging (start with --debug)


Exception in thread "main" 
org.springframework.beans.factory.BeanCreationException: Error creating 
bean with name 'application': Injection of autowired dependencies failed; 
nested exception is java.lang.IllegalArgumentException: requirement failed: 
Can't work with a null graph database
at 
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at 
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at 
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at 
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at 
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at 
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at 
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at 
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at 
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:648)
at 
org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
at 
org.springframework.boot.SpringApplication.run(SpringApplication.java:909)
at 
org.springframework.boot.SpringApplication.run(SpringApplication.java:898)
at com.me.nosql.neo4j.hello.Application.main(Application.java:86)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.IllegalArgumentException: requirement failed: Can't 
work with a null graph database
at scala.Predef$.require(Predef.scala:233)
at org.neo4j.cypher.ExecutionEngine.<init>(ExecutionEngine.scala:35)
at 
org.neo4j.cypher.javacompat.ExecutionEngine.<init>(ExecutionEngine.java:53)
at 
org.neo4j.cypher.javacompat.ExecutionEngine.<init>(ExecutionEngine.java:43)
at 
org.springframework.data.neo4j.support.query.CypherQueryEngineImpl.<init>(CypherQueryEngineImpl.java:41)
at 
org.springframework.data.neo4j.support.DelegatingGraphDatabase.createCypherQueryEngine(DelegatingGraphDatabase.java:219)
at 
org.springframework.data.neo4j.support.DelegatingGraphDatabase.queryEngine(DelegatingGraphDatabase.java:208)
at 
org.springframework.data.neo4j.support.DelegatingGraphDatabase.queryEngine(DelegatingGraphDatabase.java:215)
at 
org.springframework.data.neo4j.support.DelegatingGraphDatabase.queryEngine(DelegatingGraphDatabase.java:201)
at 
org.springframework.data.neo4j.support.schema.SchemaIndexProvider.<init>(SchemaIndexProvider.java:36)
at 
org.springframework.data.neo4j.support.DelegatingGraphDatabase.<init>(DelegatingGraphDatabase.java:72)
at 
org.springframework.data.neo4j.support.DelegatingGraphDatabase.<init>(DelegatingGraphDatabase.java:67)
at 
org.springframework.data.neo4j.config.Neo4jConfiguration.graphDatabase(Neo4jConfiguration.java:257)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at 
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:589)
at 
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at 
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
... 20 more

Process finished with exit code 1


Application.java
-----------------------

import java.io.File;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.kernel.EmbeddedGraphDatabase;
import org.neo4j.kernel.impl.util.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.data.neo4j.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.config.Neo4jConfiguration;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.data.neo4j.core.GraphDatabase;
import org.springframework.stereotype.Controller;

@Controller
@EnableAutoConfiguration
@EnableNeo4jRepositories
public class Application extends Neo4jConfiguration implements 
CommandLineRunner {

    @Bean
    GraphDatabaseService graphDatabaseService() {
        return new GraphDatabaseFactory().newEmbeddedDatabase( 
"accessingdataneo4j.db" );
    }

    @Autowired
    PersonRepository personRepository;

    @Autowired
    GraphDatabase graphDatabase;

    public void run(String... args) throws Exception {

        Person greg = new Person("Greg");
        Person roy = new Person("Roy");
        Person craig = new Person("Craig");

        System.out.println("Before linking up with Neo4j...");
        for (Person person : new Person[]{greg, roy, craig}) {
            System.out.println(person);
        }

        Transaction tx = graphDatabase.beginTx();
        try {
            personRepository.save(greg);
            personRepository.save(roy);
            personRepository.save(craig);

            greg = personRepository.findByName(greg.name);
            greg.worksWith(roy);
            greg.worksWith(craig);
            personRepository.save(greg);

            roy = personRepository.findByName(roy.name);
            roy.worksWith(craig);
            // We already know that roy works with greg
            personRepository.save(roy);

            // We already know craig works with roy and greg

            tx.success();
        } finally {
            tx.close();
        }

        System.out.println("Lookup each person by name...");
        for (String name : new String[]{greg.name, roy.name, craig.name}) {
            System.out.println(personRepository.findByName(name));
        }

        System.out.println("Looking up who works with Greg...");
        for (Person person : personRepository.findByTeammatesName("Greg")) {
            System.out.println(person.name + " works with Greg.");
        }
    }

    public static void main(String[] args) throws Exception {
        FileUtils.deleteRecursively(new File("accessingdataneo4j.db"));

        SpringApplication.run(Application.class, args);
    }

}
pom.xml
-------------
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-neo4j</artifactId>
            <version>3.1.0.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-context</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-tx</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework</groupId>
                    <artifactId>spring-aspects</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
        </dependency>
    </dependencies>


-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to neo4j+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to