My project consists of several @Configuration
annotated bean configuration classes.
How can I print out all the configuration classes that have been loaded?
I have read these questions but they don't seem to apply to my use case:
My project consists of several @Configuration
annotated bean configuration classes.
How can I print out all the configuration classes that have been loaded?
I have read these questions but they don't seem to apply to my use case:
You can use ApplicationContext#getBeansWithAnnotation
. It will not only take classes with @Configuration
annotation but also classes annotated with annotations meta-annotated with @Configuration
, like @SpringBootApplication
:
@Bean
ApplicationRunner applicationRunner(ApplicationContext applicationContext) {
return args -> {
applicationContext.getBeansWithAnnotation(Configuration.class)
.entrySet()
.stream()
.filter(entry -> entry.getValue().getClass().getPackage().getName().startsWith("com.your.package"))
.forEach(entry -> {
System.out.println("name: " + entry.getKey() + ", bean: " + entry.getValue());
});
};
}