springboot 运行main方法报错:java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
现象:项目中的@Test方法中正常引用到Logger,但是在main方法中运行就会报错:java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
解决:
寻找项目中的slf4j-api引用地方,发现<scope>属性为provided时间,IDEA运行就会报错ClassNotFound异常,将属性改为compile后,再运行就正常了。
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
<scope>compile</scope>
</dependency>