获取spring中所有的bean名称
前置条件:所在bean实现
ApplicationContextAware接口
配置一个
private Set<String> beanNames=new HashSet<>(500);
容器
实现过程:
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
for(String beanName:applicationContext.getBeanDefinitionNames()){
beanNames.add(beanName);
}
}
@GetMapping("obtain.bean.names")
public R obtainBeanNames(){
return R.success(beanNames);
}
获取:{{url}}/obtain.bean.names