简体   繁体   English

Velocity 中 SimpleLogger (SLF4j) 的配置错误

[英]Configuration error with SimpleLogger (SLF4j) in Velocity

I am having some difficulty configuring some loggers for velocity in Spring. I am using Velocity 2.1, Spring 5.2.2 and SLF4J 2.0.0我在为 Spring 中的速度配置一些记录器时遇到一些困难。我使用的是 Velocity 2.1、Spring 5.2.2 和 SLF4J 2.0.0

org.slf4j.simple.SimpleLogger object set as runtime.log.instance is not a valid org.slf4j.Logger implementation.

I am trying to configure some old discarded Spring classes to build a JAR (new versions of them) to use in my application.我正在尝试配置一些旧的废弃 Spring 类来构建 JAR(它们的新版本)以在我的应用程序中使用。

velocityEngine.setProperty(RuntimeConstants.RUNTIME_LOG_INSTANCE, (new SimpleLoggerFactory()).getLogger("SpringVelocityConfiguration"));

This is how I am doing it.我就是这样做的。 But I keep getting the exception.但我不断得到例外。

The line throwing the exception is from org.apache.velocity.runtime.RuntimeInstance :抛出异常的行来自org.apache.velocity.runtime.RuntimeInstance

 if (Logger.class.isAssignableFrom(o.getClass()))

From what I saw from the API documentation, SimpleLogger is a subclass to Logger.从我从 API 文档中看到的,SimpleLogger 是 Logger 的子类。 So it should work out isn't it?所以它应该解决,不是吗?

Adding the dependency tree as requested:根据要求添加依赖树:

[INFO] --- maven-dependency-plugin:3.1.1:tree (default-cli) @ spring-velocity-support ---
[INFO] com.gtt.palabs:spring-velocity-support:jar:0.0.1-SNAPSHOT
[INFO] +- commons-logging:commons-logging:jar:1.2:provided
[INFO] +- javax.servlet:javax.servlet-api:jar:4.0.1:provided
[INFO] +- org.slf4j:slf4j-api:jar:2.0.0-alpha1:provided
[INFO] +- org.slf4j:slf4j-simple:jar:2.0.0-alpha1:compile
[INFO] +- org.springframework:spring-context:jar:5.2.2.RELEASE:provided
[INFO] |  +- org.springframework:spring-aop:jar:5.2.2.RELEASE:provided
[INFO] |  +- org.springframework:spring-beans:jar:5.2.2.RELEASE:provided
[INFO] |  \- org.springframework:spring-expression:jar:5.2.2.RELEASE:provided
[INFO] +- org.springframework:spring-core:jar:5.2.2.RELEASE:provided
[INFO] |  \- org.springframework:spring-jcl:jar:5.2.2.RELEASE:provided
[INFO] +- org.springframework:spring-web:jar:5.2.2.RELEASE:provided
[INFO] +- org.springframework:spring-webmvc:jar:5.2.2.RELEASE:provided
[INFO] +- org.apache.velocity:velocity-engine-core:jar:2.1:provided
[INFO] |  \- org.apache.commons:commons-lang3:jar:3.9:compile
[INFO] +- org.apache.velocity.tools:velocity-tools-generic:jar:3.0:provided
[INFO] |  +- commons-beanutils:commons-beanutils:jar:1.9.3:compile
[INFO] |  |  \- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] |  +- org.apache.commons:commons-digester3:jar:3.2:compile
[INFO] |  |  \- cglib:cglib:jar:2.2.2:compile
[INFO] |  |     \- asm:asm:jar:3.3.1:compile
[INFO] |  \- com.github.cliftonlabs:json-simple:jar:3.0.2:provided
[INFO] \- org.apache.velocity.tools:velocity-tools-view:jar:3.0:compile

Error:错误:

org.apache.velocity.exception.VelocityException: Error initializing log: com.gtt.logicalprovisioning.velocity.utilities.VelocityLogger object set as runtime.log.instance is not a valid org.slf4j.Logger implementation.
    at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:958)
    at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:260)
    at org.apache.velocity.app.VelocityEngine.init(VelocityEngine.java:90)
    at com.gtt.logicalprovisioning.velocity.utilities.VelocityBuilderSystem.<init>(VelocityBuilderSystem.java:69)
    at com.gtt.logicalprovisioning.ipflex.VelocityBuilderAction.processAction(VelocityBuilderAction.java:158)
    at com.gtt.logicalprovisioning.rtp.BaseActionListType.run(BaseActionListType.java:72)
Caused by: org.apache.velocity.exception.VelocityException: com.gtt.logicalprovisioning.velocity.utilities.VelocityLogger object set as runtime.log.instance is not a valid org.slf4j.Logger implementation.
    at org.apache.velocity.runtime.RuntimeInstance.initializeLog(RuntimeInstance.java:931)
    ... 5 more

The log line says it all:日志行说明了一切:

org.apache.velocity.exception.VelocityException: Error initializing log:
com.gtt.logicalprovisioning.velocity.utilities.VelocityLogger
object set as runtime.log.instance
is not a valid org.slf4j.Logger implementation.

It means that the old Spring classes you are working with do overwrite the runtime.instance.log property before Velocity initialization is carried on.这意味着您正在使用的旧 Spring 类会在进行 Velocity 初始化之前覆盖 runtime.instance.log 属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM