10

我有一个嵌入式 neo4j 服务器,带有在 Play 2.0.1 应用程序中工作的管理控制台。我最近升级到与 DeadBolt 兼容的候选版本,发现应用程序不再运行。

要启动服务器,我正在执行以下操作:

    graphDb = (GraphDatabaseAPI) new GraphDatabaseFactory()
                .newEmbeddedDatabaseBuilder(CONF_DBMETA_LOCATION)
                .setConfig(ShellSettings.remote_shell_enabled, "true")
                .newGraphDatabase();
        ServerConfigurator config;
        config = new ServerConfigurator(graphDb);
        // let the server endpoint be on a custom port

        srv = new WrappingNeoServerBootstrapper(graphDb, config);
        srv.start();

不幸的是,我得到:

> java.lang.RuntimeException:
> org.neo4j.kernel.lifecycle.LifecycleException: Component
> 'org.neo4j.kernel.logging.LogbackService@4c043845' failed to
> initialize. Please see attached cause exception.

我尝试从添加了 neo4j-server 的 Build.scala 中删除 slf4j 和 logback 依赖项,但无济于事。似乎 Neo4j 正在加载错误的 logback.xml。此外,如果我将 notTransitive() 添加到 neo4j-server 依赖项中,启动时的 logback.xml 警告就会消失。我想 Neo4j 特定的 logback.xml 嵌入在 jar 中并导致了问题。我看到的一种潜在解决方案是通过代码编写自定义配置,但我不确定如何执行此操作。有什么想法吗?作为参考,我在启动时收到这些错误:

>     22:11:05,124 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find
> resource [logback.groovy]
>     22:11:05,125 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find
> resource [logback-test.xml]
>     22:11:05,125 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource
> [logback.xml] at
> [jar:file:/Users/steve/Code/play-2.1-RC1/repository/local/play/play_2.10/2.1-RC1/jars/play_2.10.jar!/logback.xml]
>     22:11:05,126 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml]
> occurs multiple times on the classpath.
>     22:11:05,126 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml]
> occurs at
> [jar:file:/Users/steve/Code/play-2.1-RC1/framework/../repository/cache/org.neo4j.app/neo4j-server/jars/neo4j-server-1.9-SNAPSHOT.jar!/logback.xml]
>     22:11:05,126 |-WARN in ch.qos.logback.classic.LoggerContext[default] - Resource [logback.xml]
> occurs at
> [jar:file:/Users/steve/Code/play-2.1-RC1/repository/local/play/play_2.10/2.1-RC1/jars/play_2.10.jar!/logback.xml]
>     22:11:05,139 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@733b8bc1 - URL
> [jar:file:/Users/steve/Code/play-2.1-RC1/repository/local/play/play_2.10/2.1-RC1/jars/play_2.10.jar!/logback.xml]
> is not of type file
>     22:11:05,265 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug
> attribute not set
>     22:11:05,614 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate
> appender of type [ch.qos.logback.core.ConsoleAppender]
>     22:11:05,625 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as
> [STDOUT]
>     22:11:05,657 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming
> default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for
> [encoder] property
>     22:11:05,707 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level
> of ROOT logger to ERROR
>     22:11:05,707 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching
> appender named [STDOUT] to Logger[ROOT]
>     22:11:05,707 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of
> configuration.
>     22:11:05,709 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@4a546701 - Registering
> current configuration as safe fallback point

有关完整的例外情况,请参见下文:

> play.api.UnexpectedException: Unexpected exception[RuntimeException:
> org.neo4j.kernel.lifecycle.LifecycleException: Component
> 'org.neo4j.kernel.logging.LogbackService@4c043845' failed to
> initialize. Please see attached cause exception.]     at
> play.core.ReloadableApplication$$anonfun$get$1$$anonfun$1.apply(ApplicationProvider.scala:134)
> ~[play_2.10.jar:2.1-RC1]  at
> play.core.ReloadableApplication$$anonfun$get$1$$anonfun$1.apply(ApplicationProvider.scala:101)
> ~[play_2.10.jar:2.1-RC1]  at scala.Option.map(Option.scala:145)
> ~[scala-library.jar:na]   at
> play.core.ReloadableApplication$$anonfun$get$1.apply(ApplicationProvider.scala:101)
> ~[play_2.10.jar:2.1-RC1]  at
> play.core.ReloadableApplication$$anonfun$get$1.apply(ApplicationProvider.scala:99)
> ~[play_2.10.jar:2.1-RC1]  at
> scala.util.Either$RightProjection.flatMap(Either.scala:523)
> [scala-library.jar:na] Caused by: java.lang.RuntimeException:
> org.neo4j.kernel.lifecycle.LifecycleException: Component
> 'org.neo4j.kernel.logging.LogbackService@4c043845' failed to
> initialize. Please see attached cause exception.  at
> org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:258)
> ~[neo4j-kernel-1.9.M03.jar:na]    at
> org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:88)
> ~[neo4j-kernel-1.9.M03.jar:na]    at
> org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:83)
> ~[neo4j-kernel-1.9.M03.jar:1.9.M03]   at
> org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:206)
> ~[neo4j-kernel-1.9.M03.jar:1.9.M03]   at
> EmbeddedGraphDB.initializeDatabase(EmbeddedGraphDB.java:70)
> ~[na:na]  at
> EmbeddedGraphDB.<init>(EmbeddedGraphDB.java:51)
> ~[na:na] Caused by: org.neo4j.kernel.lifecycle.LifecycleException:
> Component 'org.neo4j.kernel.logging.LogbackService@4c043845' failed to
> initialize. Please see attached cause exception.  at
> org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:471)
> ~[neo4j-kernel-1.9.M03.jar:1.9.M03]   at
> org.neo4j.kernel.lifecycle.LifeSupport.init(LifeSupport.java:62)
> ~[neo4j-kernel-1.9.M03.jar:1.9.M03]   at
> org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:96)
> ~[neo4j-kernel-1.9.M03.jar:1.9.M03]   at
> org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:245)
> ~[neo4j-kernel-1.9.M03.jar:na]    at
> org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:88)
> ~[neo4j-kernel-1.9.M03.jar:na]    at
> org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:83)
> ~[neo4j-kernel-1.9.M03.jar:1.9.M03] Caused by:
> org.neo4j.kernel.lifecycle.LifecycleException: Component
> 'org.neo4j.kernel.logging.LogbackService$1@1955bd61' was successfully
> initialized, but failed to start. Please see attached cause exception.
>   at
> org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:495)
> ~[neo4j-kernel-1.9.M03.jar:1.9.M03]   at
> org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:105)
> ~[neo4j-kernel-1.9.M03.jar:1.9.M03]   at
> org.neo4j.kernel.logging.LogbackService.init(LogbackService.java:106)
> ~[neo4j-kernel-1.9.M03.jar:1.9.M03]   at
> org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.init(LifeSupport.java:465)
> ~[neo4j-kernel-1.9.M03.jar:1.9.M03]   at
> org.neo4j.kernel.lifecycle.LifeSupport.init(LifeSupport.java:62)
> ~[neo4j-kernel-1.9.M03.jar:1.9.M03]   at
> org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:96)
> ~[neo4j-kernel-1.9.M03.jar:1.9.M03] Caused by:
> java.lang.NoSuchMethodError:
> org.codehaus.janino.ClassBodyEvaluator.setImplementedInterfaces([Ljava/lang/Class;)V
>   at
> ch.qos.logback.core.joran.conditional.PropertyEvalScriptBuilder.build(PropertyEvalScriptBuilder.java:48)
> ~[logback-core.jar:na]    at
> ch.qos.logback.core.joran.conditional.IfAction.begin(IfAction.java:67)
> ~[logback-core.jar:na]    at
> ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:276)
> ~[logback-core.jar:na]    at
> ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:148)
> ~[logback-core.jar:na]    at
> ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:130)
> ~[logback-core.jar:na]    at
> ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:50)
> ~[logback-core.jar:na]

EDIT1 更多细节

我从 play_2.10.jar 中删除了 logback.xml 文件,并且在播放应用程序启动时不再从 logback 中收到重复警告。

然后,我尝试将 neo4j logback.xmlplay2.1 logback.xml 的内容作为 custom-logback.xml 放置在我的 play 项目的根目录中。与 Play.application().path() 相同的路径 也许这是 neo4j 拾取它的错误位置?

在查看依赖项时,我有一个 neo4j-server 需要的 janino。此外,我没有看到用于记录的 jar 中的任何冲突,但也许我遗漏了一些东西。这是我的“播放依赖项”的依赖层次结构:

https://gist.github.com/4559389

我还尝试将 Play2.1 wiki 上列出的默认配置复制到 custom-logback.xml 中,但没有成功:

<configuration>

  <conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
     <file>${application.home}/logs/application.log</file>
     <encoder>
       <pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
     </encoder>
   </appender>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%coloredLevel %logger{15} - %message%n%xException{5}</pattern>
    </encoder>
  </appender>

  <logger name="play" level="INFO" />
  <logger name="application" level="INFO" />

  <root level="ERROR">
    <appender-ref ref="STDOUT" />
    <appender-ref ref="FILE" />
  </root>

</configuration>

编辑 2

绝对似乎是 logback 依赖项的问题。Neo4j 依赖于 0.9.30,play 似乎依赖于 1.0.7。我猜当库被 ?janino? 加载时,这些版本之间存在 api 变化。它找不到合适的方法。仍然不确定如何在 logback.xml 中正确指定以在运行时选择正确的依赖项。 Play2.1RC1 Logback 依赖 Neo4j Logback 依赖

图表由 yed + sbt-dependency-graph 生成。

4

4 回答 4

5

关于由于 Play 2.1 的较新版本的 logback 与 Neo4j 不兼容而引发的 Neo4j 生命周期异常。我遇到了这个问题,最后只是通过将它放在我的 Build.scala 的项目依赖项中,将 Play 的 logback 覆盖到旧的兼容版本:

"ch.qos.logback" % "logback-core" % "1.0.3" force(), // this should override the Play version
"ch.qos.logback" % "logback-classic" % "1.0.3" force(),

为了更好地衡量,我还尝试通过设置 SBT 的ivyXML参数来排除任何 log4j 传递依赖项:

ivyXML :=
  <dependencies>
    <exclude module="log4j"/>
  </dependencies>

这显然是一个脆弱的修复,但至少对于 Play 2.1-RC2,它似乎有效。我在实际配置 Neo4j 的日志记录时仍然遇到问题,所以我稍后会尝试更新这个答案。

更新:由于我是 Logback 的新手,我在使用 Play/Neo4j 配置它时遇到了一些困难。为了防止 Logback 出错并将我淹没在状态消息中,我需要custom-logback.xml在我的 Play 应用程序的 conf 目录中放置一个名为的文件。我认为 Neo4j 日志配置需要这个。我的包含以下内容:

<included>
    <logger name="eu.mypackage" level="info">
    </logger>

    <logger name="org.neo4j" level="warn">
    </logger>

    <root level="warn">
    </root>
</included>

同样在我的 conf 目录中,我似乎需要一个名为logback.properties(在我的情况下)只包含这一行的文件:

CONSOLE_LEVEL=ERROR

(Logback 专家,请随时纠正任何问题。)

于 2013-01-26T20:20:23.810 回答
2

您似乎遇到了两个不同的问题。一是Play提供了一个与Neo冲突的logback.xml文件。其次,您似乎在类路径上有两个版本的 logback,我猜这会导致 NoSuchMethodError 异常。如果您可以删除 Play logback.xml 文件并将该内容放入名为“/custom-logback.xml”的文件中(Neo 将通过我们的 logback 配置包含该文件),然后确保您只有一个版本的 Logback(或具体来说,Janino),这应该会有所帮助。

于 2013-01-17T06:59:06.517 回答
1

最终我无法解决 Play 2.1、Neo4J 和 logback 之间的依赖问题。我确信它是一个简单快捷的修复,但我不确定如何在不明确修改任何一个包依赖项的情况下进行操作。相反,我暂时选择使用Neo4J Java REST 绑定来替换嵌入式服务器。运行良好,并且在本机 API 和 REST 包装器之间存在一些小问题。我将嵌入式服务器的依赖项留在了 Build.scala 中,并将嵌入式和 REST 服务从一个公共接口中分离出来,以便可以在运行时指定它们。我想理想情况下,这两者都应该是 Play 的插件......

于 2013-01-20T16:58:57.967 回答
0

这听起来可能与上面的问题描述完全无关,但是:

我们的问题——我在 Mac 上,我在 Ubuntu 上的同事——原来是库依赖项被拉到 Play 的 /lib 目录中,而该目录不应该存在(无论出于何种原因),在我们的例子中是两个版本Janino - 2.5.10 和 2.6.1,删除旧版本解决了问题。

我的同事提到了一些关于用于标识这两个版本的命名约定的差异,这可能导致了问题。

总而言之;在某些情况下,请检查您的 /lib 目录中是否存在非必要或意外的库。

于 2013-09-19T14:30:11.603 回答