使用Logback.xml播放2.1和Neo4J WrappingNeoServer错误

时间:2013-01-17 06:00:52

标签: neo4j slf4j logback playframework-2.1

我有一个嵌入式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.

我尝试从我的Build.scala中删除slf4j和logback依赖项,其中添加了neo4j-server但无济于事。似乎neo4j正在加载错误的logback.xml。此外,如果我将noTransitive()添加到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.xml play2.1 logback.xml的内容作为custom-logback.xml放在我的play项目的根目录中。与Play.application()相同的路径.path()也许这是neo4j拾取它的错误位置?

在查看依赖关系时,我有一个neo4j-server所需的janino。此外,我没有看到罐子里的任何日志冲突,但也许我错过了一些东西。这是我的依赖层次结构来自'play dependencies':

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并且看起来依赖于1.0.7。我猜这些版本之间有一个api更改,当库被加载时?janino?它找不到合适的方法。仍然不确定如何在logback.xml中正确指定以在运行时选择适当的依赖项。 Play2.1RC1 Logback Dependency Neo4j Logback Dependency

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

4 个答案:

答案 0 :(得分:5)

关于因为Play 2.1的新版本的logback与Neo4j不兼容而引发的Neo4j生命周期异常。我遇到了这个问题,并最终将Play的logback重写为旧的兼容版本,方法是将它放在我的Build.scala的项目依赖项中:

"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错误并在状态消息中淹没我,我需要在我的Play应用程序的conf目录中放置一个名为custom-logback.xml的文件。我认为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专家,随时纠正其中任何一项。)

答案 1 :(得分:2)

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

答案 2 :(得分:1)

最终我无法解决Play 2.1,Neo4J和logback之间的依赖问题。我确信它是一个简单快速的解决方案,但我不确定如何在不明确修改任何包依赖的情况下解决它。相反,我选择暂时使用Neo4J Java REST binding替换嵌入式服务器。运行良好,只有一些轻微的打嗝与本机API和REST包装器之间的差异。我在Build.scala中保留了嵌入式服务器的依赖关系,并将嵌入式和REST服务从公共接口拆分,以便可以在运行时指定它们。我觉得理想情况下这些都应该是Play的插件......

答案 3 :(得分:0)

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

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

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

总结如此;在某些情况下,请检查/ lib目录中的非必要或意外库。