删除commons-logging并使用slf4j会导致spring错误
具体来说,我仅使用 spring 通过 ApplicationContext 配置我的项目。在我的 spring xml 中,我通过 PropertyPlaceholderConfigurer 加载一些 bean 属性。每当在依赖项中我将 commons-logging-xx 与 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 支持的任何框架。很多时候,用 jcl-over-slf4j.jar 替换 commons-logging.jar 将立即永久解决与公共日志记录相关的类加载器问题。
Specifically, I use spring only for configuring my project through ApplicationContext. In my spring xml I load some bean properties through PropertyPlaceholderConfigurer. Whenever in the dependencies I swap commons-logging-x.x with jcl-slf4j.jar the loading of the context fails with ClassNotFoundExceptions on the placeholder substitutions. Example:
In my spring.xml there is:
<bean id="testbean" class="${testbean.implementingClass}"/>
where testbean.implementingClass is defined in spring.properties:
testbean.implementingClass=my.implementation.TestClass
If I run the project using commons-logging jar all works perfectly. If I change it to jcl-slf4j then I get ClassNotFoundException that the class [${testbean.implementingClass}] was not found, i.e. it does not do the placeholder substituion. Has anyone observed this?
EDIT: My problem doesnt have to do with the jars because:
From http://www.slf4j.org/legacy.html :
Our JCL over SLF4J implementation will allow you to migrate to SLF4J gradually, especially if some of the libraries your software depends on continue to use JCL for the foreseeable future. You can immediately enjoy the benefits of SLF4J's reliability and preserve backward compatibility at the same time. Just replace commons-logging.jar with jcl-over-slf4j.jar. Subsequently, the selection of the underlying logging framework will be done by SLF4J instead of JCL but without the class loader headaches plaguing JCL. The underlying logging framework can be any of the frameworks supported by SLF4J. Often times, replacing commons-logging.jar with jcl-over-slf4j.jar will immediately and permanently solve class loader issues related to commons logging.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用
jcl-slf4j
时,您必须确保已从项目中排除所有commons-logging
依赖项。确保类路径中的任何位置都没有 commons-logging jar。When you use
jcl-slf4j
, you have to make sure you have excluded allcommons-logging
dependencies from your project. Make sure there is no commons-logging jar anywhere in the classpath.