@SpringBootTest测试报java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration.错误

 使用SpringBootTest测试的时候报错:java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration, you need to use @ContextConfiguration or @SpringBootTest(classes=...) with your test

@SpringBootTest测试报java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration.错误_第1张图片

 Test1类

@RunWith(SpringRunner.class)
@SpringBootTest
public class Test1 {
	@Test
	public void getLines() throws IOException, InterruptedException{
		Cal cal = new CalImpl();
		System.out.println(cal.add(1, 2));
	}
}

原因是我建springboot项目的时候漏写了一个注解:@SpringBootApplication,加上即可

@ContextConfiguration
@EnableAutoConfiguration
@ComponentScan
@SpringBootApplication
public class App {
      public static void main(String[] args) {
          SpringApplication.run(App.class, args);
      }
      
}

结果:

@SpringBootTest测试报java.lang.IllegalStateException: Unable to find a @SpringBootConfiguration.错误_第2张图片

你可能感兴趣的:(#,异常解决方案,springboot)