-1

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:

Jon Tan
  • 1,461
  • 3
  • 17
  • 33

1 Answers1

1

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());
    });
  };
}
Maciej Walkowiak
  • 12,372
  • 59
  • 63