Print all the Spring beans that are loaded - Spring Boot
Object-Oriented Design practice on Codemia
Turn requirements into classes, and defend the design, on the problems that come up in OOD rounds.
Introduction
Listing the beans loaded into a Spring Boot application is a useful debugging tool when you want to verify component scanning, understand auto-configuration, or confirm which implementation actually ended up in the application context. The raw bean list can be noisy, so the practical goal is usually not just to print everything, but to print it in a way that helps you answer a specific wiring question.
Print Bean Names from the Application Context
The simplest option is to ask the ApplicationContext for all bean definition names and print them during startup.
Sorting matters. Without it, the output order depends on registration timing and is much harder to scan.
Include the Bean Type
Names alone are not always enough. Spring can register proxies, generated infrastructure beans, and multiple beans with similar names. Printing the resolved type makes the output much more useful.
This makes it much easier to see whether a bean came from your package, from Spring Boot auto-configuration, or from a library starter.
Filter the Output to Your Code
Real applications often contain hundreds of beans. If you only care about your own components, filter by package prefix or bean name pattern.
Filtering turns a wall of framework internals into something you can actually use while debugging.
Use Actuator for Runtime Inspection
If you want to inspect beans without adding custom startup code, Spring Boot Actuator exposes structured context information. Enable the endpoint and query it over HTTP.
This is often a better option in staging or shared environments where startup logs are noisy or hard to retrieve.
Know What the Bean List Does Not Tell You
A printed bean list shows what was registered, not why it was registered or whether it was selected for a particular injection point. If you are debugging conditional configuration, the condition evaluation report can be more informative than the bean dump itself.
Add this during troubleshooting:
That causes Spring Boot to print the auto-configuration condition report at startup, which explains why certain configuration classes matched or were skipped.
Common Pitfalls
The most common mistake is assuming that bean presence means your application is using that bean. Spring may have several candidates of the same interface type, and an injection point may be selecting one through @Primary, qualifiers, or conditional configuration.
Another issue is printing the full context in production logs. Bean names can reveal internal structure, cloud integrations, data access layers, and security wiring. That is acceptable during focused debugging, but it should not become a permanent default.
It is also easy to ignore parent and child contexts. In more complex applications, especially tests or servlet-based setups, the context you print may not be the only one in play.
Finally, do not use bean dumping as a substitute for better diagnostics. If the real question is "why did my bean not load", the condition report and package scan boundaries often answer that faster than a raw list.
Summary
- Use
ApplicationContext.getBeanDefinitionNames()to print loaded bean names. - Include bean types and sorting to make the output readable.
- Filter by package or name when the context is too large to inspect directly.
- Prefer Actuator for structured runtime inspection.
- Use Boot's debug condition report when you need to know why a bean was or was not created.
Related reading
- Property getters and setters
- Protocol can only be used as a generic constraint because it has Self or associatedType requirements
- RabbitMQ with Unity IOC Container in .NET
- Reflection generic get field value
- Print an integer in binary format in Java
- Print the data in ResultSet along with column names
- required a bean of type 'org.springframework.security.core.userdetails.UserDetailsService' that could not be found
- Resource vs Autowired

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Object-Oriented Design practice on Codemia
Turn requirements into classes, and defend the design, on the problems that come up in OOD rounds.