@Component
public class BeanUtils implements ApplicationContextAware {
private ApplicationContext context;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
if (this.context == null){
this.context = applicationContext;
}
}
public String[] getBeans(){
return context.getBeanDefinitionNames();
}
}
@SpringBootTest
class XxxApplicationTests {
@Resource
private BeanUtils beanUtil;
@Test
void contextLoads() {
String[] str=beanUtil.getBeans();
for (String string : str) {
System.out.println("..."+string);
}
}
}