WHen deploying my Spring / Hibernate application, I get the following warning related to logging:
在部署我的Spring / Hibernate应用程序时,我收到以下与日志记录相关的警告:
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
Surprising to me was the lack of information from a Google / SO search. The only thing relevant was this SO post Problem with Commons Logging / Log4j setup in spring webapp with tomcat 6
让我感到惊讶的是Google / SO搜索中缺少信息。唯一相关的是使用tomcat 6在Spring webapp中设置Commons Logging / Log4j的SO问题
However, this is even beyond me. Can somebody clarify the logging systems in play here, or point me to a RECENT resource on the matter (there are some ancient google search results that don't really apply). Specifically, the issues I'm wrestling with are:
然而,这甚至超出了我的范围。有人可以澄清这里正在使用的日志系统,或者指向我关于此事的最新资源(有一些古老的谷歌搜索结果并不真正适用)。具体来说,我正在努力解决的问题是:
-
The distinction among commons-logging, log4j, slf4j and JCL. My understanding is that slf4j is a wrapper, while commons-logging and log4j are actual implementations. I don't know where JCL fits in.
commons-logging,log4j,slf4j和JCL之间的区别。我的理解是slf4j是一个包装器,而commons-logging和log4j是实际的实现。我不知道JCL适合哪里。
-
How to configure logging for Spring. What does in the web.xml file, do i need a log4j.properties file or a log4j.xml file? Where does it go, in WEB-INF? Does anything go in my applicationContext.xml file? (sorry but I need to start from zero here).
如何配置Spring的日志记录。在web.xml文件中,我需要一个log4j.properties文件还是一个log4j.xml文件?它在哪里,在WEB-INF?我的applicationContext.xml文件中有什么内容吗? (对不起,但我需要从零开始)。
-
I am using Hibernate in my project and including via Maven. It seems that Hibernate uses slf4j-simple. I have seen warnings saying that I can't have slf4j-simple and slf4j-log4j both on the classpath. I have not included slf4j-log4j as a dependency, but Hibernate must be including it. How do i solve this problem? Can I force Hibernate to use log4j instead?
我在我的项目中使用Hibernate,包括通过Maven。似乎Hibernate使用slf4j-simple。我看到警告说我不能在类路径上有slf4j-simple和slf4j-log4j。我没有将slf4j-log4j作为依赖项包含在内,但Hibernate必须包含它。我该如何解决这个问题?我可以强制Hibernate使用log4j吗?
Any help would be greatly appreciated. Thanks.
任何帮助将不胜感激。谢谢。
edit:
Thanks for all the answers so far. I am giving these suggestions a try. What about spring web-app specifically? I've seen examples of listeners and parameters and whatnot put into the web.xml file. Is this also required?
感谢到目前为止的所有答案。我试试这些建议。春季网络应用程序具体怎么样?我已经看到了侦听器和参数的示例以及未放入web.xml文件的内容。这还需要吗?
5 个解决方案
#1
12
-
commons-logging and SLF4J are both API wrappers around other logging implementations. SLF4J is the more modern of the two, and rather more capable. Log4j is a logging implementation, and pretty much the defacto standard. JUL (short for
java.util.logging
) is the (generally awful) logging implementation that comes with the JRE. Another log implementation is logback, which is slowly gaining traction, but not at all widespread yet. - commons-logging和SLF4J都是围绕其他日志记录实现的API包装器。 SLF4J是两者中比较现代的,而且更有能力。 Log4j是一个日志记录实现,几乎是事实上的标准。 JUL(java.util.logging的缩写)是JRE附带的(通常很糟糕的)日志记录实现。另一个日志实现是logback,它正在慢慢获得牵引力,但还没有普及。
-
log4j.properties
andlog4j.xml
are different ways of configuring log4j, both are equally valid. Which one you use is up to you, although some application servers dictate one or the other. Read the log4j manual to find out how to configure this. - log4j.properties和log4j.xml是配置log4j的不同方式,两者都同样有效。您使用哪一个取决于您,尽管某些应用程序服务器会指示其中一个。阅读log4j手册以了解如何配置它。
- If Hibernate uses SLF4J as its API, that's the choice of the Hibernate developers. However, you can choose which logging implementation SLF4J will delegate to. Again, read the slf4j manual to find out how to select your chosen implementation.
- 如果Hibernate使用SLF4J作为其API,那么这就是Hibernate开发人员的选择。但是,您可以选择SLF4J将委派给哪个日志记录实现。再次阅读slf4j手册,了解如何选择所选的实现。
Yes, it's all rather confusing. Given an open choice, SLF4J and Logback is the most capable combination, but you usually don't get an open choice. Different frameworks (like Hibernate and Spring) will potentially use different logging APIs, usually commons-logging or SLF4J, but you can get all those APIs to eventually log to the same underlying implementation (usually log4j).
是的,这一切都让人感到困惑。如果有一个开放的选择,SLF4J和Logback是最强大的组合,但你通常不会有一个开放的选择。不同的框架(如Hibernate和Spring)可能会使用不同的日志API,通常是commons-logging或SLF4J,但是你可以让所有这些API最终登录到相同的底层实现(通常是log4j)。
#2
4
- The distinction among commons-logging, log4j, slf4j and JCL. My understanding is that slf4j is a wrapper, while commons-logging and log4j are actual implementations. I don't know where JCL fits in.
- commons-logging,log4j,slf4j和JCL之间的区别。我的理解是slf4j是一个包装器,而commons-logging和log4j是实际的实现。我不知道JCL适合哪里。
Jakarta Commons Logging (JCL) and Simple Logging Facade for Java SLF4J are both abstractions for various logging frameworks e.g. java.util.logging, log4j and logback, allowing the end user to plug in the desired logging framework at deployment time. Commons Logging is known to suffers from class loader problems which is what SLF4J tries to solve (SLF4J is known to be a cleaner library).
用于Java SLF4J的Jakarta Commons Logging(JCL)和Simple Logging Facade都是各种日志记录框架的抽象,例如: java.util.logging,log4j和logback,允许最终用户在部署时插入所需的日志记录框架。众所周知,Commons Logging会遇到类加载器问题,这是SLF4J试图解决的问题(已知SLF4J是一个更清晰的库)。
Having that said, the fact is that Spring uses Jakarta Commons Logging API (see Logging Dependencies in Spring): Spring is compiled against JCL and Spring makes JCL Log
objects available for classes that extend Spring. The is actually the only mandatory external dependency in Spring. This choice has been made because many other frameworks where also using it (e.g. Struts). The idea was to avoid having to have multiple facade libraries on the class path when building applications ("A" for Spring, "B" for Struts, etc). It is however possible to replace JCL by SLF4J if you want to (SFL4J provides bindings to logging frameworks but also a "JCL to SLF4J" bridge). See the mentioned post Logging Dependencies in Spring for all the details.
话虽如此,事实是Spring使用Jakarta Commons Logging API(请参阅Spring中的Logging Dependencies):Spring是针对JCL编译的,Spring使JCL Log对象可用于扩展Spring的类。实际上它是Spring中唯一的强制外部依赖。之所以做出这样的选择是因为许多其他框架也在使用它(例如Struts)。这个想法是为了避免在构建应用程序时在类路径上有多个Facade库(Spring为“A”,Struts为“B”等)。但是,如果您愿意,可以用SLF4J替换JCL(SFL4J提供了对日志框架的绑定,但也提供了“JCL到SLF4J”桥接器)。有关所有详细信息,请参阅Spring中提到的Logging Dependencies。
- How to configure logging for Spring. What does in the web.xml file, do i need a log4j.properties file or a log4j.xml file? Where does it go, in WEB-INF? Does anything go in my applicationContext.xml file? (sorry but I need to start from zero here).
- 如何配置Spring的日志记录。在web.xml文件中,我需要一个log4j.properties文件还是一个log4j.xml文件?它在哪里,在WEB-INF?我的applicationContext.xml文件中有什么内容吗? (对不起,但我需要从零开始)。
To log, you have 1. to decide which implementation you want to use (java.util.logging, log4j or logback), 2. to put the chosen one on the classpath if required (java.util.logging is in Java SE so it doesn't require extra libraries) and 3. to configure it (by putting a config file on the classpath). If you choose to use log4j, just add its jar and a log4j.properties
or a more fancy (but more verbose) log4j.xml
(this is just another format for the configuration) to the classpath.
要进行日志记录,您需要1.确定要使用的实现(java.util.logging,log4j或logback),2。如果需要,将选定的实现放在类路径上(java.util.logging在Java SE中,所以它不需要额外的库)和3.配置它(通过在类路径上放置一个配置文件)。如果您选择使用log4j,只需将其jar和log4j.properties或更精细(但更详细)的log4j.xml(这只是配置的另一种格式)添加到类路径中。
- I am using Hibernate in my project and including via Maven. It seems that Hibernate uses slf4j-simple. I have seen warnings saying that I can't have slf4j-simple and slf4j-log4j both on the classpath. I have not included slf4j-log4j as a dependency, but Hibernate must be including it. How do i solve this problem? Can I force Hibernate to use log4j instead?
- 我在我的项目中使用Hibernate,包括通过Maven。似乎Hibernate使用slf4j-simple。我看到警告说我不能在类路径上有slf4j-simple和slf4j-log4j。我没有将slf4j-log4j作为依赖项包含在内,但Hibernate必须包含它。我该如何解决这个问题?我可以强制Hibernate使用log4j吗?
Hibernate utilizes Simple Logging Facade for Java (SLF4J) and, indeed, you can't have several bindings (e.g. slf4j-simple.jar
and slf4j-logj12.jar
) on the classpath at the same time. Here, you are very likely getting slf4j-simple.jar
transitively from another dependency. To solve this problem, run mvn dependency:tree
to figure out from where it's coming from and exclude it if required.
Hibernate使用Simple Logging Facade for Java(SLF4J),实际上,你不能同时在类路径上有几个绑定(例如slf4j-simple.jar和slf4j-logj12.jar)。在这里,您很可能从另一个依赖项传递slf4j-simple.jar。要解决此问题,请运行mvn dependency:tree以确定它来自何处,并在需要时将其排除。
And by the way, in your case, I would configure Spring to use SLF4J as Hibernate is using it. Follow the steps in the link mentioned in the first paragraph for that. And I would use logback as logging framework (which the successor of log4j), this is where things happen now.
顺便说一句,在你的情况下,我会配置Spring使用SLF4J,因为Hibernate正在使用它。请按照第一段中提到的链接中的步骤进行操作。我会使用logback作为日志框架(log4j的后继者),这就是现在发生的事情。
#3
2
You need a log4j.properties file in your classpath. Here is a minimal properties file I happened to have created yesterday:
您需要在类路径中使用log4j.properties文件。这是我昨天碰巧创建的最小属性文件:
log4j.logger.BillReview=INFO,BillReviewLog
log4j.appender.BillReviewLog=org.apache.log4j.RollingFileAppender
log4j.appender.BillReviewLog.File=BillReview.log
log4j.appender.BillReviewLog.Append=true
log4j.appender.BillReviewLog.MaxFileSize=5000KB
log4j.appender.BillReviewLog.MaxBackupIndex=5
log4j.appender.BillReviewLog.layout=org.apache.log4j.PatternLayout
log4j.appender.BillReviewLog.layout.ConversionPattern=%c %p %-10.10X{server} %-4.4X{user} %d{ISO8601} %m%n
Put that into a log4j.properties file, change all the references to 'BillReview' to something more like your project and that'll log to a file and stop those messages.
将其放入log4j.properties文件中,将对“BillReview”的所有引用更改为更类似于项目的内容,并将其记录到文件并停止这些消息。
Your questions about which logging framework are largely personal choice. Log4j is the old standard and it works fine, Commons logging and slf4j are newer APIs and allow some more complicated use cases.
您对哪个日志框架主要是个人选择的疑问。 Log4j是旧标准,它工作正常,Commons logging和slf4j是更新的API,允许一些更复杂的用例。
#4
1
I'll let some more experienced Gurus than I answer the first bullet.
我会让一些更有经验的大师比我回答第一个子弹。
Answering your second bullet...
回答你的第二个子弹......
You can use either a log4j.properties or log4j.xml file (it doesn't matter which). Whatever you choose you should add it to your classpath (typically it should go in the same directory as your source code). If you are using Spring, a nice way to break your src directory up into logical portions is by using the following directory structure...
您可以使用log4j.properties或log4j.xml文件(无关紧要)。无论你选择什么,你都应该将它添加到你的类路径中(通常它应该与源代码位于同一目录中)。如果您使用的是Spring,那么将src目录分解为逻辑部分的好方法是使用以下目录结构...
src/main/java -- put main source here
src/main/resources -- put resources used by you main source here
src/test/java -- put test source here (for tests)
src/test/resources -- put resources for tests here
src / main / java - 把main源放在这里src / main / resources - 把你主要使用的资源放在这里src / test / java - 把测试源放到这里(用于测试)src / test / resources - 放置资源在这里测试
You would therefore put your log4j.properties in the src/test/resources directory.
因此,您将log4j.properties放在src / test / resources目录中。
Answering your third bullet...
回答你的第三个子弹......
You can exclude a dependency within a dependency in you pom.xml file by doing the following...
您可以通过执行以下操作来排除pom.xml文件中依赖项中的依赖项...
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
<version>${xbean.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
#5
0
I had problems in the same area while running my tests. I eventually noticed that junit was bringing in slf4j-nop
as a dependency, in addition to the slf4j-log4j12
that I wanted. Once I excluded slf4j-nop
, it started working.
我在运行测试时在同一区域遇到了问题。我最终注意到除了我想要的slf4j-log4j12之外,junit还引入了slf4j-nop作为依赖项。一旦我排除了slf4j-nop,它就开始工作了。
#1
12
-
commons-logging and SLF4J are both API wrappers around other logging implementations. SLF4J is the more modern of the two, and rather more capable. Log4j is a logging implementation, and pretty much the defacto standard. JUL (short for
java.util.logging
) is the (generally awful) logging implementation that comes with the JRE. Another log implementation is logback, which is slowly gaining traction, but not at all widespread yet. - commons-logging和SLF4J都是围绕其他日志记录实现的API包装器。 SLF4J是两者中比较现代的,而且更有能力。 Log4j是一个日志记录实现,几乎是事实上的标准。 JUL(java.util.logging的缩写)是JRE附带的(通常很糟糕的)日志记录实现。另一个日志实现是logback,它正在慢慢获得牵引力,但还没有普及。
-
log4j.properties
andlog4j.xml
are different ways of configuring log4j, both are equally valid. Which one you use is up to you, although some application servers dictate one or the other. Read the log4j manual to find out how to configure this. - log4j.properties和log4j.xml是配置log4j的不同方式,两者都同样有效。您使用哪一个取决于您,尽管某些应用程序服务器会指示其中一个。阅读log4j手册以了解如何配置它。
- If Hibernate uses SLF4J as its API, that's the choice of the Hibernate developers. However, you can choose which logging implementation SLF4J will delegate to. Again, read the slf4j manual to find out how to select your chosen implementation.
- 如果Hibernate使用SLF4J作为其API,那么这就是Hibernate开发人员的选择。但是,您可以选择SLF4J将委派给哪个日志记录实现。再次阅读slf4j手册,了解如何选择所选的实现。
Yes, it's all rather confusing. Given an open choice, SLF4J and Logback is the most capable combination, but you usually don't get an open choice. Different frameworks (like Hibernate and Spring) will potentially use different logging APIs, usually commons-logging or SLF4J, but you can get all those APIs to eventually log to the same underlying implementation (usually log4j).
是的,这一切都让人感到困惑。如果有一个开放的选择,SLF4J和Logback是最强大的组合,但你通常不会有一个开放的选择。不同的框架(如Hibernate和Spring)可能会使用不同的日志API,通常是commons-logging或SLF4J,但是你可以让所有这些API最终登录到相同的底层实现(通常是log4j)。
#2
4
- The distinction among commons-logging, log4j, slf4j and JCL. My understanding is that slf4j is a wrapper, while commons-logging and log4j are actual implementations. I don't know where JCL fits in.
- commons-logging,log4j,slf4j和JCL之间的区别。我的理解是slf4j是一个包装器,而commons-logging和log4j是实际的实现。我不知道JCL适合哪里。
Jakarta Commons Logging (JCL) and Simple Logging Facade for Java SLF4J are both abstractions for various logging frameworks e.g. java.util.logging, log4j and logback, allowing the end user to plug in the desired logging framework at deployment time. Commons Logging is known to suffers from class loader problems which is what SLF4J tries to solve (SLF4J is known to be a cleaner library).
用于Java SLF4J的Jakarta Commons Logging(JCL)和Simple Logging Facade都是各种日志记录框架的抽象,例如: java.util.logging,log4j和logback,允许最终用户在部署时插入所需的日志记录框架。众所周知,Commons Logging会遇到类加载器问题,这是SLF4J试图解决的问题(已知SLF4J是一个更清晰的库)。
Having that said, the fact is that Spring uses Jakarta Commons Logging API (see Logging Dependencies in Spring): Spring is compiled against JCL and Spring makes JCL Log
objects available for classes that extend Spring. The is actually the only mandatory external dependency in Spring. This choice has been made because many other frameworks where also using it (e.g. Struts). The idea was to avoid having to have multiple facade libraries on the class path when building applications ("A" for Spring, "B" for Struts, etc). It is however possible to replace JCL by SLF4J if you want to (SFL4J provides bindings to logging frameworks but also a "JCL to SLF4J" bridge). See the mentioned post Logging Dependencies in Spring for all the details.
话虽如此,事实是Spring使用Jakarta Commons Logging API(请参阅Spring中的Logging Dependencies):Spring是针对JCL编译的,Spring使JCL Log对象可用于扩展Spring的类。实际上它是Spring中唯一的强制外部依赖。之所以做出这样的选择是因为许多其他框架也在使用它(例如Struts)。这个想法是为了避免在构建应用程序时在类路径上有多个Facade库(Spring为“A”,Struts为“B”等)。但是,如果您愿意,可以用SLF4J替换JCL(SFL4J提供了对日志框架的绑定,但也提供了“JCL到SLF4J”桥接器)。有关所有详细信息,请参阅Spring中提到的Logging Dependencies。
- How to configure logging for Spring. What does in the web.xml file, do i need a log4j.properties file or a log4j.xml file? Where does it go, in WEB-INF? Does anything go in my applicationContext.xml file? (sorry but I need to start from zero here).
- 如何配置Spring的日志记录。在web.xml文件中,我需要一个log4j.properties文件还是一个log4j.xml文件?它在哪里,在WEB-INF?我的applicationContext.xml文件中有什么内容吗? (对不起,但我需要从零开始)。
To log, you have 1. to decide which implementation you want to use (java.util.logging, log4j or logback), 2. to put the chosen one on the classpath if required (java.util.logging is in Java SE so it doesn't require extra libraries) and 3. to configure it (by putting a config file on the classpath). If you choose to use log4j, just add its jar and a log4j.properties
or a more fancy (but more verbose) log4j.xml
(this is just another format for the configuration) to the classpath.
要进行日志记录,您需要1.确定要使用的实现(java.util.logging,log4j或logback),2。如果需要,将选定的实现放在类路径上(java.util.logging在Java SE中,所以它不需要额外的库)和3.配置它(通过在类路径上放置一个配置文件)。如果您选择使用log4j,只需将其jar和log4j.properties或更精细(但更详细)的log4j.xml(这只是配置的另一种格式)添加到类路径中。
- I am using Hibernate in my project and including via Maven. It seems that Hibernate uses slf4j-simple. I have seen warnings saying that I can't have slf4j-simple and slf4j-log4j both on the classpath. I have not included slf4j-log4j as a dependency, but Hibernate must be including it. How do i solve this problem? Can I force Hibernate to use log4j instead?
- 我在我的项目中使用Hibernate,包括通过Maven。似乎Hibernate使用slf4j-simple。我看到警告说我不能在类路径上有slf4j-simple和slf4j-log4j。我没有将slf4j-log4j作为依赖项包含在内,但Hibernate必须包含它。我该如何解决这个问题?我可以强制Hibernate使用log4j吗?
Hibernate utilizes Simple Logging Facade for Java (SLF4J) and, indeed, you can't have several bindings (e.g. slf4j-simple.jar
and slf4j-logj12.jar
) on the classpath at the same time. Here, you are very likely getting slf4j-simple.jar
transitively from another dependency. To solve this problem, run mvn dependency:tree
to figure out from where it's coming from and exclude it if required.
Hibernate使用Simple Logging Facade for Java(SLF4J),实际上,你不能同时在类路径上有几个绑定(例如slf4j-simple.jar和slf4j-logj12.jar)。在这里,您很可能从另一个依赖项传递slf4j-simple.jar。要解决此问题,请运行mvn dependency:tree以确定它来自何处,并在需要时将其排除。
And by the way, in your case, I would configure Spring to use SLF4J as Hibernate is using it. Follow the steps in the link mentioned in the first paragraph for that. And I would use logback as logging framework (which the successor of log4j), this is where things happen now.
顺便说一句,在你的情况下,我会配置Spring使用SLF4J,因为Hibernate正在使用它。请按照第一段中提到的链接中的步骤进行操作。我会使用logback作为日志框架(log4j的后继者),这就是现在发生的事情。
#3
2
You need a log4j.properties file in your classpath. Here is a minimal properties file I happened to have created yesterday:
您需要在类路径中使用log4j.properties文件。这是我昨天碰巧创建的最小属性文件:
log4j.logger.BillReview=INFO,BillReviewLog
log4j.appender.BillReviewLog=org.apache.log4j.RollingFileAppender
log4j.appender.BillReviewLog.File=BillReview.log
log4j.appender.BillReviewLog.Append=true
log4j.appender.BillReviewLog.MaxFileSize=5000KB
log4j.appender.BillReviewLog.MaxBackupIndex=5
log4j.appender.BillReviewLog.layout=org.apache.log4j.PatternLayout
log4j.appender.BillReviewLog.layout.ConversionPattern=%c %p %-10.10X{server} %-4.4X{user} %d{ISO8601} %m%n
Put that into a log4j.properties file, change all the references to 'BillReview' to something more like your project and that'll log to a file and stop those messages.
将其放入log4j.properties文件中,将对“BillReview”的所有引用更改为更类似于项目的内容,并将其记录到文件并停止这些消息。
Your questions about which logging framework are largely personal choice. Log4j is the old standard and it works fine, Commons logging and slf4j are newer APIs and allow some more complicated use cases.
您对哪个日志框架主要是个人选择的疑问。 Log4j是旧标准,它工作正常,Commons logging和slf4j是更新的API,允许一些更复杂的用例。
#4
1
I'll let some more experienced Gurus than I answer the first bullet.
我会让一些更有经验的大师比我回答第一个子弹。
Answering your second bullet...
回答你的第二个子弹......
You can use either a log4j.properties or log4j.xml file (it doesn't matter which). Whatever you choose you should add it to your classpath (typically it should go in the same directory as your source code). If you are using Spring, a nice way to break your src directory up into logical portions is by using the following directory structure...
您可以使用log4j.properties或log4j.xml文件(无关紧要)。无论你选择什么,你都应该将它添加到你的类路径中(通常它应该与源代码位于同一目录中)。如果您使用的是Spring,那么将src目录分解为逻辑部分的好方法是使用以下目录结构...
src/main/java -- put main source here
src/main/resources -- put resources used by you main source here
src/test/java -- put test source here (for tests)
src/test/resources -- put resources for tests here
src / main / java - 把main源放在这里src / main / resources - 把你主要使用的资源放在这里src / test / java - 把测试源放到这里(用于测试)src / test / resources - 放置资源在这里测试
You would therefore put your log4j.properties in the src/test/resources directory.
因此,您将log4j.properties放在src / test / resources目录中。
Answering your third bullet...
回答你的第三个子弹......
You can exclude a dependency within a dependency in you pom.xml file by doing the following...
您可以通过执行以下操作来排除pom.xml文件中依赖项中的依赖项...
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
<version>${xbean.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
#5
0
I had problems in the same area while running my tests. I eventually noticed that junit was bringing in slf4j-nop
as a dependency, in addition to the slf4j-log4j12
that I wanted. Once I excluded slf4j-nop
, it started working.
我在运行测试时在同一区域遇到了问题。我最终注意到除了我想要的slf4j-log4j12之外,junit还引入了slf4j-nop作为依赖项。一旦我排除了slf4j-nop,它就开始工作了。