我如何诊断这个 neo4j-ogm / mvn spring-boot:运行 问题?

How can I diagnose this neo4j-ogm / mvn spring-boot:run issue?

我希望有人可以建议我可以用来诊断此问题的策略。我认为这可能是 spring-boot maven 插件中的错误。

我正在开发一个使用 neo4j-ogm 实现持久性的应用程序。

当我在 eclipse 中或作为可执行 jar 启动它时,应用程序启动并运行得很好。

当我使用 mvn spring-boot:run 启动它时,它不起作用并抛出以下堆栈跟踪。

关于 spring-boot maven 插件可能做错了什么的任何指示?

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

附加信息

作为可执行 jar 打印输出:

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

mvn spring-boot:run 开始输出:

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

会话工厂代码

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

失败的代码 (as excerpted from the Neo4J GITHUB) 是第 158 行 `

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         }

` 这意味着 typeInfo 或 typeInfo.annotationsInfo() 为空,仅在来自 Maven 的 运行 的情况下。

假设其他一切都相同,mvn spring-boot:run 必须使用与 eclipse 不同的类路径。按照输出中的建议尝试 mvn --debug -e -X spring-boot:run。首先检查类路径以查找 jar 版本中的差异以及 Eclipse 正在获取的顺序与 mvn spring-boot:run 正在获取的顺序。