【问题标题】:removing commons-logging and using slf4j causes errors in spring删除 commons-logging 和使用 slf4j 会导致 spring 出错
【发布时间】:2010-06-28 21:02:22
【问题描述】:

具体来说,我只使用 spring 来通过 ApplicationContext 配置我的项目。在我的 spring xml 中,我通过 PropertyPlaceholderConfigurer 加载了一些 bean 属性。每当在依赖项中我将 commons-logging-x.x 与 jcl-slf4j.jar 交换时,上下文的加载都会失败,并在占位符替换上出现 ClassNotFoundExceptions。示例:

在我的 spring.xml 中有:

<bean id="testbean" class="${testbean.implementingClass}"/>

其中 testbean.implementingClass 在 spring.properties 中定义:

testbean.implementingClass=my.implementation.TestClass

如果我使用 commons-logging jar 运行项目,一切都会完美。如果我将其更改为 jcl-slf4j,那么我会得到 ClassNotFoundException 类 [${testbean.implementingClass}] 未找到,即它不执行占位符替换。有没有人观察到这一点?

编辑:我的问题与罐子无关,因为: 来自http://www.slf4j.org/legacy.html

我们的 JCL over SLF4J 实现将允许您逐步迁移到 SLF4J,特别是如果您的软件所依赖的某些库在可预见的未来继续使用 JCL。您可以立即享受 SLF4J 的可靠性带来的好处,同时保持向后兼容性。只需将 commons-logging.jar 替换为 jcl-over-slf4j.jar。随后,底层日志框架的选择将由 SLF4J 而不是 JCL 来完成,但没有困扰 JCL 的类加载器问题。底层日志框架可以是 SLF4J 支持的任何框架。通常,将 commons-logging.jar 替换为 jcl-over-slf4j.jar 将立即永久解决与公共日志相关的类加载器问题。

【问题讨论】:

    标签: java spring slf4j


    【解决方案1】:

    当您使用jcl-slf4j 时,您必须确保您已从项目中排除了所有commons-logging 依赖项。确保类路径中的任何地方都没有 commons-logging jar。

    【讨论】:

    • 很遗憾没有。我也认为这是问题所在,但不是......我的类路径没有 jcl
    猜你喜欢
    • 2019-05-12
    • 2023-03-31
    • 1970-01-01
    • 2013-03-10
    • 2020-11-05
    • 1970-01-01
    • 1970-01-01
    • 2014-05-04
    • 1970-01-01
    相关资源
    最近更新 更多