Java 有没有一种方法可以通过组件扫描查看哪些bean被注册?

Java 有没有一种方法可以通过组件扫描查看哪些bean被注册?,java,spring,spring-boot,Java,Spring,Spring Boot,我试图确定哪些bean是通过Spring引导组件扫描机制获取的,哪些是通过自动配置获取的,等等。我还没有找到一种方法来实现这一点,这可能吗 我想知道这一点,因为我将使用spring上下文索引器在我的应用程序JAR中创建一个META-INF/spring.components文件。但是,我引入了其他库/jar,我想知道如果这些jar提供依赖组件扫描的bean进行注册,这是否会破坏我的应用程序。我不知道是否有更好的方法来实现这一点,但您可以通过注释ConfigServletWebServerAppl

我试图确定哪些bean是通过Spring引导组件扫描机制获取的,哪些是通过自动配置获取的,等等。我还没有找到一种方法来实现这一点,这可能吗


我想知道这一点,因为我将使用
spring上下文索引器
在我的应用程序JAR中创建一个
META-INF/spring.components
文件。但是,我引入了其他库/jar,我想知道如果这些jar提供依赖组件扫描的bean进行注册,这是否会破坏我的应用程序。

我不知道是否有更好的方法来实现这一点,但您可以通过
注释ConfigServletWebServerApplicationContext::getBeanDefinition
(可以自动关联上下文)


如果其他人知道更干净的方法,我也想知道如何使用。

为什么不直接获取bean的类并过滤掉扫描包中没有的类?
// Bean from autoconfiguration
// Can check the factory bean name and see that it has 
// the "org.springframework.boot.autoconfigure" package
// to determine that it's probably from autoconfiguration
BeanDefinition autoConfigDef = context.getBeanDefinition("dispatcherServletRegistration");
autoConfigDef.getFactoryBeanName(); // org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration$DispatcherServletRegistrationConfiguration
autoConfigDef.getFactoryMethodName(); // dispatcherServletRegistration

// Bean from my configuration @Bean + @Configuration
// If it has a factory bean name and it doesn't have the 
// Spring autoconfiguration package, it's probably from one of our
// own configurations
BeanDefinition myConfigDef = context.getBeanDefinition("myConverter");
myConfigDef.getFactoryBeanName(); // me.demo.MyConfiguration
myConfigDef.getFactoryBeanMethod(); // myConverter

// Bean annotated with @Component and discovered via component scan
// Doesn't have a configuration associated with it, so it was probably
// detected via the @Component annotation
BeanDefinition componentDef = context.getBeanDefinition("myController");
componentDef.getFactoryBeanName(); // null
componentDef.getFactoryBeanMethod(); // null