1、已知的最简单的代码
@SpringBootApplication
public class SbrtestApplication {
public static void main(String[] args) {
SpringApplication.run(SbrtestApplication.class, args);
}
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("Let's inspect the beans provided by Spring Boot:");
String[] beanNames = ctx.getBeanDefinitionNames();
// 排列
Arrays.sort(beanNames);
String message = "no";
for (String beanName : beanNames) {
System.out.println(beanName);
// 判断是否包含
if ("helloController".equals(beanName)){
message = "yes";
break;
}
}
System.out.println(message);
};
}
}
运行后如下图所示: