查看springboot在启动的时候为我们注入了哪些bean

在程序入口加入:

@SpringBootApplication
public class SpringbootFirstApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootFirstApplication.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);
            for (String beanName : beanNames) {
                System.out.println(beanName);
            }

        };
    }

}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

程序输出:

Let’s inspect the beans provided by Spring Boot: 
basicErrorController 
beanNameHandlerMapping 
beanNameViewResolver 
characterEncodingFilter 
commandLineRunner 
conventionErrorViewResolver 
defaultServletHandlerMapping 
defaultViewResolver 
dispatcherServlet 
dispatcherServletRegistration 
duplicateServerPropertiesDetector 
embeddedServletContainerCustomizerBeanPostProcessor 
error 
errorAttributes 
errorPageCustomizer 
errorPageRegistrarBeanPostProcessor

…. 
….

在程序启动的时候,springboot自动诸如注入了40-50个bean.

猜你喜欢

转载自blog.csdn.net/m0_37450089/article/details/81182677