-1

I'm hoping someone can suggest a strategy I can use to diagnose this. I think it could be a bug in the spring-boot maven plugin.

I'm working on an application using neo4j-ogm for persistence.

When I launch it in eclipse, or as an executable jar, the application starts up and runs just fine.

When I launch it using mvn spring-boot:run it does not work and throws the following stack trace.

Any pointers on what the spring-boot maven plugin might be doing incorrectly?

21:05:56.553 [nz.co.********.console.main.Application.main()] INFO  o.s.b.a.l.AutoConfigurationReportLoggingInitializer -

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


21:05:56.602 [nz.co.********.console.main.Application.main()] ERROR o.s.boot.SpringApplication - Application startup failed
java.lang.IllegalStateException: Failed to execute CommandLineRunner
        at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:676) ~[spring-boot-1.2.6.RELEASE.jar:1.2.6.RELEASE]
        at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:691) ~[spring-boot-1.2.6.RELEASE.jar:1.2.6.RELEASE]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) ~[spring-boot-1.2.6.RELEASE.jar:1.2.6.RELEASE]
        at nz.co.********.console.main.Application.main(Application.java:15) [classes/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_25]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_25]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_25]
        at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_25]
        at org.springframework.boot.maven.RunMojo$LaunchRunner.run(RunMojo.java:418) [spring-boot-maven-plugin-1.2.6.RELEASE.jar:1.2.6.RELEASE]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_25]
Caused by: java.lang.NullPointerException: null
        at org.neo4j.ogm.session.response.SessionResponseHandler.lookup(SessionResponseHandler.java:158) ~[neo4j-ogm-1.1.2.jar:na]
        at org.neo4j.ogm.session.response.SessionResponseHandler.loadById(SessionResponseHandler.java:152) ~[neo4j-ogm-1.1.2.jar:na]
        at org.neo4j.ogm.session.delegates.LoadOneDelegate.load(LoadOneDelegate.java:45) ~[neo4j-ogm-1.1.2.jar:na]
        at org.neo4j.ogm.session.Neo4jSession.load(Neo4jSession.java:104) ~[neo4j-ogm-1.1.2.jar:na]
        at nz.co.********.core.MemberAccountService.loadMemberByEmailAddressPasswordAccount(MemberAccountService.java:126) ~[********-core-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
        at nz.co.********.console.menu.Menu.login(Menu.java:33) ~[classes/:na]
        at nz.co.********.console.menu.Menu.login(Menu.java:95) ~[classes/:na]
        at nz.co.********.console.menu.MainMenu.processUserInput(MainMenu.java:110) ~[classes/:na]
        at nz.co.********.console.menu.Menu.processUserInput(Menu.java:79) ~[classes/:na]
        at nz.co.********.console.main.ConsoleUI.run(ConsoleUI.java:65) ~[classes/:na]
        at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:673) ~[spring-boot-1.2.6.RELEASE.jar:1.2.6.RELEASE]
        ... 9 common frames omitted
21:05:56.604 [nz.co.********.console.main.Application.main()] INFO  o.s.c.a.AnnotationConfigApplicationContext - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@327b0992: startup date [Thu Sep 24 21:05:40 CEST 2015]; root of context hierarchy
21:05:56.642 [nz.co.********.console.main.Application.main()] INFO  o.s.j.e.a.AnnotationMBeanExporter - Unregistering JMX-exposed beans on shutdown
[WARNING]
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:483)
        at org.springframework.boot.maven.RunMojo$LaunchRunner.run(RunMojo.java:418)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalStateException: Failed to execute CommandLineRunner
        at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:676)
        at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:691)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:322)
        at nz.co.********.console.main.Application.main(Application.java:15)
        ... 6 more
Caused by: java.lang.NullPointerException
        at org.neo4j.ogm.session.response.SessionResponseHandler.lookup(SessionResponseHandler.java:158)
        at org.neo4j.ogm.session.response.SessionResponseHandler.loadById(SessionResponseHandler.java:152)
        at org.neo4j.ogm.session.delegates.LoadOneDelegate.load(LoadOneDelegate.java:45)
        at org.neo4j.ogm.session.Neo4jSession.load(Neo4jSession.java:104)
        at nz.co.********.core.MemberAccountService.loadMemberByEmailAddressPasswordAccount(MemberAccountService.java:126)
        at nz.co.********.console.menu.Menu.login(Menu.java:33)
        at nz.co.********.console.menu.Menu.login(Menu.java:95)
        at nz.co.********.console.menu.MainMenu.processUserInput(MainMenu.java:110)
        at nz.co.********.console.menu.Menu.processUserInput(Menu.java:79)
        at nz.co.********.console.main.ConsoleUI.run(ConsoleUI.java:65)
        at org.springframework.boot.SpringApplication.runCommandLineRunners(SpringApplication.java:673)
        ... 9 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.938 s
[INFO] Finished at: 2015-09-24T21:05:56+01:00
[INFO] Final Memory: 34M/594M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.2.6.RELEASE:run (default-cli) on project ********-console: An exception occured while running. null: InvocationTargetException: Failed to execute CommandLineRunner: NullPointerException -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Additional information

Starting as an executable jar prints out:

16:50:54.854 [main] INFO  o.n.o.m.info.ClassFileProcessor - 34 classes loaded in 1927 milliseconds 

Starting with mvn spring-boot:run prints out:

17:02:02.250 [nz.co.********.console.main.Application.main()] INFO  o.n.o.m.info.ClassFileProcessor - 0 classes loaded in 3 milliseconds

Session Factory Code

import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.apache.log4j.Logger;
import org.neo4j.ogm.session.Session;
import org.neo4j.ogm.session.SessionFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.stereotype.Component;

@Component
public class Neo4jSessionFactory implements FactoryBean<Session> {

    private final static SessionFactory sessionFactory = new SessionFactory("nz.co.*****.pojos");

    @Inject private CoreProperties config;

    private Logger logger = Logger.getLogger(this.getClass);

    @Override
    public Session getObject() {
        return sessionFactory.openSession(config.getHost(), config.getUsername(), config.getPassword());
    }

    @Override
    public Class<?> getObjectType() {
        return Session.class;
    }

    @Override
    public boolean isSingleton() {
        return false;
    }

    @PostConstruct
    public void printInfo() { 
        logger.info("DbLocation: " + config.getHost());
    }
}
John Deverall
  • 5,954
  • 3
  • 27
  • 37
  • Where do you set up the SessionFactory? Is it set up before Menu.login is called? When the application starts up, there should be INFO log output stating "x classes loaded in y milliseconds" - can you share that line? – Luanne Sep 25 '15 at 02:53
  • Thank you for looking at this. I've added the 'x classes line' to the question and it shows you're obviously on the right track :) I hadn't noticed that. I'll investigate whether the SessionFactory is loading before or after Menu.login but I assume it is loaded before – John Deverall Sep 27 '15 at 15:46
  • @Luanne, yes the SessionFactory is always setup prior. I've posted my SessionFactory code in the question. – John Deverall Sep 27 '15 at 19:19
  • We have an ogm app with spring boot here https://github.com/neo4j-examples/neo4j-ogm-university/tree/spring-boot Perhaps you could take a look or share your project. As long as your session is set up correctly, you should not be running into this issue – Luanne Sep 28 '15 at 05:33
  • @ Luanne, I've added you to our repository on github. I've updated our README.md with skype contact information. – John Deverall Sep 28 '15 at 08:43

1 Answers1

1

The code that is failing (as excerpted from the Neo4J GITHUB) is line 158 of `

155     private <T> T lookup(Class<T> type, Long id) {
156         Object ref;
157         ClassInfo typeInfo = metaData.classInfo(type.getName());
158         if (typeInfo.annotationsInfo().get(RelationshipEntity.CLASS) == null) {
159             ref = mappingContext.getNodeEntity(id);
160         } else {
161             ref = mappingContext.getRelationshipEntity(id);
162         }
163         try {
164             return type.cast(ref);
165         }
166         catch (ClassCastException cce) {
167             return null;
168         }

` That means that either typeInfo or typeInfo.annotationsInfo() are null, only in the case of running from Maven.

Assuming everything else is equal, mvn spring-boot:run must be using a different classpath than eclipse. Try mvn --debug -e -X spring-boot:run as suggested in your output. Start by examining classpath looking for differences in the jar versions and order that Eclipse is picking up versus what mvn spring-boot:run is picking up.

Derek Bennett
  • 807
  • 1
  • 7
  • 14