代码之家  ›  专栏  ›  技术社区  ›  Paralife

删除commons日志记录并使用slf4j会在spring中导致错误

  •  1
  • Paralife  · 技术社区  · 15 年前

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

    在my spring.xml中有:

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

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

    testbean.implementingClass=my.implementation.TestClass
    

    如果我使用commons logging jar运行这个项目,那么一切都很好。如果将其更改为jcl-slf4j,则会得到类notfoundexception,即找不到类[${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支持的任何一个框架,通常情况下,用jcl-over-SLF4J.jar替换commons-logging.jar将立即永久地解决与commons日志相关的类加载器问题。

    1 回复  |  直到 15 年前
        1
  •  1
  •   Dragisa Krsmanovic    15 年前

    当你使用 jcl-slf4j commons-logging 项目的依赖项。确保类路径中没有commons日志记录jar。