在SpringBoot中获取某个注解标记的`BeanName`

来源:互联网 发布:淘宝怎么开网店步骤 编辑:程序博客网 时间:2024/06/07 12:00
  1. 要查找的类的范围必须是Spring Bean的实例。
  2. 实现ApplicationListener<ContextRefreshedEvent>接口,实现其方法。
 @Override    public void onApplicationEvent(ContextRefreshedEvent event) {        Map<String, Object> beans = event.getApplicationContext().getBeansWithAnnotation(CrawlUrl.class);//实例名,该实例        String[] beanNamesForAnnotation = event.getApplicationContext().getBeanNamesForAnnotation(CrawlUrl.class);//实例    }
原创粉丝点击