打印容器的Beans

邓尼茨我今天去赶集 2021年03月22日 701次浏览
public class MyApplication implements CommandLineRunner

@Resource
private ApplicationContext appContext;
/**
     * CommandLineRunner ,打印spring容器中的bean
     *
     * @param args 参数
     */
    @Override
    public void run(String... args) {
        String[] beans = appContext.getBeanDefinitionNames();
        Arrays.sort(beans);
        for (String bean : beans) {
            log.info(bean + " is type of " + appContext.getBean(bean).getClass());
        }
    }