这@SpringBootApplication
是一个元注释,它应用的注释比您替换它的注释更多:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = {
@Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {
如果您不想使用@SpringBootApplication
,请尝试使用以下所有注释来注释您的类:
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan
在您的情况下,@SpringBootConfiguration
缺少。
下次运行测试时,在SpringBootTestContextBootstrapper.java中的各个点放置调试断点以查看幕后情况。
但我认为这些行表明问题出在哪里:
Class<?> found = new SpringBootConfigurationFinder()
.findFromClass(mergedConfig.getTestClass());
Assert.state(found != null,
"Unable to find a @SpringBootConfiguration, you need to use "
+ "@ContextConfiguration or @SpringBootTest(classes=...) "
+ "with your test");