我之前在Play 2.0.1应用中嵌入了一个带有管理控制台的neo4j服务器。最近我升级了版本以适配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正在加载错误的logback.xml文件。另外,如果在neo4j-server依赖项中添加notTransitive()函数,则启动时的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文件,并且不再在play应用程序启动时收到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,而Play则依赖于1.0.7。我猜想这两个版本之间存在一个api更改,当?janino?加载库时找不到适当的方法。仍然不确定如何在logback.xml中正确指定以在运行时选择适当的依赖项。
图表是由yed + sbt-dependency-graph生成的。