{"id":2745,"date":"2025-08-19T21:34:18","date_gmt":"2025-08-19T13:34:18","guid":{"rendered":"https:\/\/www.ddosidc.com\/wp\/?p=2745"},"modified":"2025-08-19T21:34:18","modified_gmt":"2025-08-19T13:34:18","slug":"%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3log4j-slf4j-impl-cannot-be-present-with-log4j-to-slf4j%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/www.ddosidc.com\/wp\/2745.html","title":{"rendered":"\u5982\u4f55\u89e3\u51b3log4j-slf4j-impl cannot be present with log4j-to-slf4j\u95ee\u9898"},"content":{"rendered":"<p><h2>\u95ee\u9898\u6982\u8ff0<\/h2>\n<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/www.ddosidc.com\/wp\/wp-content\/uploads\/2025\/05\/zfaIBjN.jpg\" alt=\"\u5982\u4f55\u89e3\u51b3log4j-slf4j-impl cannot be present with log4j-to-slf4j\u95ee\u9898\" title=\"\u5982\u4f55\u89e3\u51b3log4j-slf4j-impl cannot be present with log4j-to-slf4j\u95ee\u9898\"><\/p>\n<p><p>\u5728Java\u751f\u6001\u7cfb\u7edf\u4e2d\uff0c\u65e5\u5fd7\u7ba1\u7406\u662f\u4e00\u4e2a\u5173\u952e\u7684\u90e8\u5206\u3002Log4j\u548cSLF4J\u662f\u4e24\u4e2a\u5e7f\u6cdb\u4f7f\u7528\u7684\u65e5\u5fd7\u6846\u67b6\u3002\u7136\u800c\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5f00\u53d1\u8005\u53ef\u80fd\u4f1a\u9047\u5230\u9519\u8bef\u63d0\u793a\uff1a\u201c<strong>log4j-slf4j-impl cannot be present with log4j-to-slf4j<\/strong>\u201d\u3002\u8fd9\u4e2a\u95ee\u9898\u901a\u5e38\u53d1\u751f\u5728\u4f9d\u8d56\u51b2\u7a81\u6216\u4e0d\u517c\u5bb9\u7684\u60c5\u51b5\u4e0b\uff0c\u672c\u6587\u5c06\u8be6\u7ec6\u63a2\u8ba8\u6b64\u95ee\u9898\u7684\u539f\u56e0\u53ca\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<\/p>\n<p><h2>\u4f9d\u8d56\u5173\u7cfb\u89e3\u6790<\/h2>\n<\/p>\n<p><p>\u8981\u7406\u89e3\u4e3a\u4ec0\u4e48\u4f1a\u51fa\u73b0\u6b64\u9519\u8bef\uff0c\u9996\u5148\u8981\u4e86\u89e3\u51e0\u4e2a\u5173\u952e\u4f9d\u8d56\uff1a<\/p>\n<\/p>\n<ul>\n<li><strong>log4j-slf4j-impl<\/strong>\uff1a\u8fd9\u662fLog4j\u7684SLF4J\u5b9e\u73b0\uff0c\u4f7f\u5f97Log4j\u53ef\u4ee5\u4e0eSLF4J\u4e00\u8d77\u4f7f\u7528\u3002<\/li>\n<li><strong>log4j-to-slf4j<\/strong>\uff1a\u5c06Log4j\u65e5\u5fd7\u8c03\u7528\u91cd\u5b9a\u5411\u5230SLF4J\u63a5\u53e3\u7684\u5e93\uff0c\u4f7f\u5f97\u53ef\u4ee5\u4f7f\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u5728\u4e0d\u540c\u7684\u65e5\u5fd7\u6846\u67b6\u4e4b\u95f4\u5207\u6362\u3002<\/li>\n<\/ul>\n<p><p>\u8fd9\u4e24\u4e2a\u5e93\u63d0\u4f9b\u4e86\u76f8\u4e92\u6392\u65a5\u7684\u529f\u80fd\uff1a\u524d\u8005\u662fLog4j\u7684\u5b9e\u73b0\uff0c\u800c\u540e\u8005\u5219\u662f\u5c06Log4j\u7684\u65e5\u5fd7\u8c03\u7528\u8f6c\u6362\u4e3aSLF4J\u7684\u65e5\u5fd7\u8c03\u7528\u3002\u5b83\u4eec\u4e0d\u80fd\u540c\u65f6\u5b58\u5728\u4e8e\u76f8\u540c\u7684\u73af\u5883\u4e2d\u3002<\/p>\n<\/p>\n<p><h2>\u64cd\u4f5c\u6b65\u9aa4<\/h2>\n<\/p>\n<p><h3>\u6b65\u9aa4\u4e00\uff1a\u68c0\u67e5\u9879\u76ee\u4f9d\u8d56<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u68c0\u67e5\u9879\u76ee\u4e2d\u7684\u4f9d\u8d56\u914d\u7f6e\uff0c\u786e\u4fdd\u6ca1\u6709\u540c\u65f6\u5305\u542b\u4e0a\u8ff0\u4e24\u4e2a\u5e93\u3002\u5bf9\u4e8e\u4f7f\u7528Maven\u7684\u9879\u76ee\uff0c\u8bf7\u67e5\u770b<code>pom.xml<\/code>\u6587\u4ef6\uff0c\u82e5\u4f7f\u7528Gradle\u7684\u9879\u76ee\uff0c\u8bf7\u67e5\u770b<code>build.gradle<\/code>\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><pre><code><\/p>\r\n<p><!-- Maven\u4f9d\u8d56\u793a\u4f8b --><\/p>\r\n<p><\/p>\r\n<p>    org.apache.logging.log4j<\/p>\r\n<p>    log4j-slf4j-impl<\/p>\r\n<p>    2.x.x<\/p>\r\n<p><\/p>\r\n\r\n<p><\/p>\r\n<p>    org.apache.logging.log4j<\/p>\r\n<p>    log4j-to-slf4j<\/p>\r\n<p>    2.x.x<\/p>\r\n<p><\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><pre><code><\/p>\r\n<p>\/\/ Gradle\u4f9d\u8d56\u793a\u4f8b<\/p>\r\n<p>implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.x.x'<\/p>\r\n<p>implementation 'org.apache.logging.log4j:log4j-to-slf4j:2.x.x'<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u6b65\u9aa4\u4e8c\uff1a\u5220\u9664\u51b2\u7a81\u4f9d\u8d56<\/h3>\n<\/p>\n<p><p>\u627e\u5230\u5e76\u79fb\u9664\u51b2\u7a81\u7684\u4f9d\u8d56\u9879\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u53ea\u9700\u8981\u4fdd\u7559\u5176\u4e2d\u4e00\u4e2a\uff0c\u6839\u636e\u4f60\u7684\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e93\u6765\u4fdd\u7559\u3002<\/p>\n<\/p>\n<ul>\n<li>\u82e5\u4f60\u9700\u8981\u4f7f\u7528SLF4J\u63a5\u53e3\u5e76\u540c\u65f6\u5e0c\u671b\u4fdd\u6301Log4j\u7684\u5b9e\u73b0\uff0c\u4fdd\u7559<strong>log4j-slf4j-impl<\/strong>\u3002<\/li>\n<li>\u82e5\u4f60\u5e0c\u671b\u5c06Log4j\u65e5\u5fd7\u8c03\u7528\u6620\u5c04\u5230SLF4J\u800c\u65e0\u9700\u4f7f\u7528Log4j\u7684\u5b9e\u73b0\uff0c\u4fdd\u7559<strong>log4j-to-slf4j<\/strong>\u3002<\/li>\n<\/ul>\n<p><pre><code><\/p>\r\n<p><!--\u4fdd\u7559log4j-slf4j-impl\u793a\u4f8b--><\/p>\r\n<p><\/p>\r\n<p>    org.apache.logging.log4j<\/p>\r\n<p>    log4j-slf4j-impl<\/p>\r\n<p>    2.x.x<\/p>\r\n<p><\/p>\r\n<p><!-- \u5220\u9664log4j-to-slf4j --><\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><pre><code><\/p>\r\n<p>\/\/\u4fdd\u7559log4j-to-slf4j\u793a\u4f8b<\/p>\r\n<p>implementation 'org.apache.logging.log4j:log4j-to-slf4j:2.x.x'<\/p>\r\n<p>\/\/ \u5220\u9664log4j-slf4j-impl<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u6b65\u9aa4\u4e09\uff1a\u9a8c\u8bc1\u4fee\u6539<\/h3>\n<\/p>\n<p><p>\u4fee\u6539\u5b8c<code>pom.xml<\/code>\u6216<code>build.gradle<\/code>\u540e\uff0c\u8fd0\u884c\u9879\u76ee\u4ee5\u786e\u8ba4\u662f\u5426\u89e3\u51b3\u4e86\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><pre><code><\/p>\r\n<p>\/\/ Maven\u7528\u6237\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4<\/p>\r\n<p>mvn clean install<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><pre><code><\/p>\r\n<p>\/\/ Gradle\u7528\u6237\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4<\/p>\r\n<p>gradle clean build<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u82e5\u8fd0\u884c\u6210\u529f\u4e14\u6ca1\u6709\u65e5\u5fd7\u9519\u8bef\u63d0\u793a\uff0c\u5219\u8868\u793a\u95ee\u9898\u5df2\u89e3\u51b3\u3002<\/p>\n<\/p>\n<p><h2>\u6ce8\u610f\u4e8b\u9879<\/h2>\n<\/p>\n<ul>\n<li>\u786e\u4fdd\u5728\u4e0d\u540c\u7684\u73af\u5883\uff08\u6bd4\u5982\u5f00\u53d1\u73af\u5883\u548c\u751f\u4ea7\u73af\u5883\uff09\u4e2d\u68c0\u67e5\u4f9d\u8d56\u914d\u7f6e\uff0c\u56e0\u4e3a\u53ef\u80fd\u5b58\u5728\u4e0d\u540c\u7684\u4f9d\u8d56\u7248\u672c\u3002<\/li>\n<li>\u5728\u6dfb\u52a0\u6216\u5220\u9664\u4f9d\u8d56\u65f6\uff0c\u5efa\u8bae\u4f7f\u7528\u7248\u672c\u7ba1\u7406\u5de5\u5177\uff08\u5982Maven\u6216Gradle\uff09\u6765\u7ba1\u7406\u4f9d\u8d56\u7684\u7248\u672c\u548c\u8303\u56f4\uff0c\u4ee5\u9632\u6b62\u7248\u672c\u4e0d\u517c\u5bb9\u3002<\/li>\n<li>\u9605\u8bfb\u76f8\u5173\u5e93\u7684\u6587\u6863\uff0c\u4e86\u89e3\u5b83\u4eec\u4e4b\u95f4\u7684\u517c\u5bb9\u6027\u548c\u9650\u5236\u3002<\/li>\n<\/ul>\n<p><h2>\u5b9e\u7528\u6280\u5de7<\/h2>\n<\/p>\n<ul>\n<li><strong>\u4f9d\u8d56\u6811<\/strong>\uff1a\u4f7f\u7528Maven\u547d\u4ee4<code>mvn dependency:tree<\/code>\u6216Gradle\u547d\u4ee4<code>gradle dependencies<\/code>\u67e5\u770b\u9879\u76ee\u4f9d\u8d56\u6811\uff0c\u4ee5\u4fbf\u66f4\u597d\u5730\u7406\u89e3\u4f9d\u8d56\u5173\u7cfb\u3002<\/li>\n<li><strong>\u7248\u672c\u9501\u5b9a<\/strong>\uff1a\u5728<code>pom.xml<\/code>\u6216<code>build.gradle<\/code>\u4e2d\u9501\u5b9a\u7279\u5b9a\u7248\u672c\uff0c\u4ee5\u907f\u514d\u4e0d\u5c0f\u5fc3\u5347\u7ea7\u5bfc\u81f4\u7684\u95ee\u9898\u3002<\/li>\n<li><strong>\u6392\u9664\u4f9d\u8d56<\/strong>\uff1a\u5728Maven\u6216Gradle\u4e2d\u6392\u9664\u5176\u4ed6\u4f9d\u8d56\uff0c\u4ee5\u907f\u514d\u5f15\u5165\u4e0d\u5fc5\u8981\u7684\u5e93\uff0c\u4f8b\u5982\uff1a<\/li>\n<\/ul>\n<p><pre><code><\/p>\r\n<p><\/p>\r\n<p>    org.apache.logging.log4j<\/p>\r\n<p>    log4j-slf4j-impl<\/p>\r\n<p>    2.x.x<\/p>\r\n<p>    <\/p>\r\n<p>        <\/p>\r\n<p>            org.apache.logging.log4j<\/p>\r\n<p>            log4j-to-slf4j<\/p>\r\n<p>        <\/p>\r\n<p>    <\/p>\r\n<p><\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><pre><code><\/p>\r\n<p>\/\/ Gradle\u793a\u4f8b<\/p>\r\n<p>implementation('org.apache.logging.log4j:log4j-slf4j-impl:2.x.x') {<\/p>\r\n<p>    exclude group: 'org.apache.logging.log4j', module: 'log4j-to-slf4j'<\/p>\r\n<p>}<\/p>\r\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\u4e0e\u64cd\u4f5c\u6b65\u9aa4\uff0c\u5e0c\u671b\u5e2e\u52a9\u5f00\u53d1\u8005\u987a\u5229\u89e3\u51b3\u201c<strong>log4j-slf4j-impl cannot be present with log4j-to-slf4j<\/strong>\u201d\u95ee\u9898\u3002\u4f9d\u8d56\u7ba1\u7406\u5728Java\u5f00\u53d1\u4e2d\u81f3\u5173\u91cd\u8981\uff0c\u52a1\u5fc5\u5728\u9879\u76ee\u5f00\u53d1\u7684\u6bcf\u4e00\u6b65\u4e2d\u4fdd\u6301\u8b66\u60d5\uff0c\u786e\u4fdd\u4f9d\u8d56\u7684\u6e05\u6670\u4e0e\u5339\u914d\u3002<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898\u6982\u8ff0 \u5728Java\u751f\u6001\u7cfb\u7edf\u4e2d\uff0c\u65e5\u5fd7\u7ba1\u7406\u662f\u4e00\u4e2a\u5173\u952e\u7684\u90e8\u5206\u3002Log4j\u548cSLF4J\u662f\u4e24\u4e2a\u5e7f\u6cdb\u4f7f\u7528\u7684\u65e5\u5fd7\u6846\u67b6\u3002\u7136\u800c\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5f00\u53d1\u8005\u53ef\u80fd\u4f1a\u9047\u5230\u9519\u8bef\u63d0\u793a\uff1a\u201clog4j-slf4j-impl cannot be present with log&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2746,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"topic":[],"class_list":["post-2745","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-baike"],"_links":{"self":[{"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/posts\/2745","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/comments?post=2745"}],"version-history":[{"count":2,"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/posts\/2745\/revisions"}],"predecessor-version":[{"id":2984,"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/posts\/2745\/revisions\/2984"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/media\/2746"}],"wp:attachment":[{"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/media?parent=2745"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/categories?post=2745"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/tags?post=2745"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.ddosidc.com\/wp\/wp-json\/wp\/v2\/topic?post=2745"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}