Get all the bean names in the spring

  Get all the bean names in the spring

  Preconditions: where the bean implementation

ApplicationContextAware interface to 
configure a
private Set <String> beanNames = new HashSet <> (500); 
container

implementation:
@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

Guess you like

Origin www.cnblogs.com/wuyouwei/p/10955480.html