本文主要是介绍CommandLineRunner的Run方法没有被进入,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
检查源码:
private void callRunners(ApplicationContext context, ApplicationArguments args) {List<Object> runners = new ArrayList<>();runners.addAll(context.getBeansOfType(ApplicationRunner.class).values());runners.addAll(context.getBeansOfType(CommandLineRunner.class).values());AnnotationAwareOrderComparator.sort(runners);for (Object runner : new LinkedHashSet<>(runners)) {if (runner instanceof ApplicationRunner) {callRunner((ApplicationRunner) runner, args);}if (runner instanceof CommandLineRunner) {callRunner((CommandLineRunner) runner, args);}}}
发现context.getBeansOfType(CommandLineRunner.class).values()的size为0.说明CommandLineRunner的实现类没有被扫描到。
因此,在启动类上加上扫描的包。
@SpringBootApplication
@ComponentScan(basePackages = {"com.cetcsa.redis","com.example.demo"})
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}}
这篇关于CommandLineRunner的Run方法没有被进入的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!