当前位置: 首页>后端>正文

SpringBoot打印所有对象

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);
        };
    }
}

运行后如下图所示:
SpringBoot打印所有对象,在这里插入图片描述,第1张


https://www.xamrdz.com/backend/3y91848977.html

相关文章: