1、getBeanNamesForType()
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(PersonConfig.class);
String[] beanNames = context.getBeanNamesForType(Person.class);
Arrays.stream(beanNames).forEach(System.out::println);
// 结果:person
2、getBeanDefinitionNames()
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(PersonConfig.class); String[] beanNames = context.getBeanDefinitionNames(); Arrays.stream(beanNames).forEach(System.out::println);
//结果:
org.springframework.context.annotation.internalConfigurationAnnotationProcessor
org.springframework.context.annotation.internalAutowiredAnnotationProcessor
org.springframework.context.annotation.internalRequiredAnnotationProcessor
org.springframework.context.annotation.internalCommonAnnotationProcessor
org.springframework.context.event.internalEventListenerProcessor
org.springframework.context.event.internalEventListenerFactory
personConfig
person