Spring-Boot自我总结-001

Spring-Boot自我总结-001

获取Spring容器自动装载的Bean

package com.xbm;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication(scanBasePackages = "com.xbm")
public class SpringBootWebApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(SpringBootWebApplication.class, args);
        String[] beanDefinitionNames = run.getBeanDefinitionNames();
        for (String beanName : beanDefinitionNames) {
            System.out.println("beanName:" + beanName);
        }
    }

}

  1. 取到可配置的容器 ConfigurableApplicationContext 对象,然后获取容器种的Bean

the end

你可能感兴趣的:(javaEE笔记,java,开发语言)