@Component @Order(value = 1) @Slf4j public class MyApplicationRunner implements ApplicationRunner {//springboot 启动完成后会走这个方法 @Autowired private ApplicationContext applicationContext;//可以得到spring的上下文 @Override public void run(ApplicationArguments args) throws Exception { int i = 1; for (String beanName : applicationContext.getBeanDefinitionNames())//获取容器中的注入的name { // log.info("{}. {}", i, applicationContext.getBean(beanName)); Object bean = applicationContext.getBean(beanName);//得到容器中所有的类 EnablePage enablePage = bean.getClass().getAnnotation(EnablePage.class);//得到加了自定义注解的类 if(!StringUtils.isEmpty(enablePage)){ String value = enablePage.value(); MyAnnotation.map.put(value,bean); } i++; } } }