Print all the Spring beans that are loaded

2020-01-29 03:32发布

Is there a way to print all the spring beans that are loaded on startup?I am using Spring 2.0.

标签: java spring
8条回答
Melony?
2楼-- · 2020-01-29 04:15

Yes, get ahold of ApplicationContext and call .getBeanDefinitionNames()

You can get the context by:

  • implementing ApplicationContextAware
  • injecting it with @Inject / @Autowired (after 2.5)
  • use WebApplicationContextUtils.getRequiredWebApplicationContext(..)

Related: You can also detect each bean's registration by registering a BeanPostprocessor bean. It will be notified for each bean.

查看更多
我只想做你的唯一
3楼-- · 2020-01-29 04:17

With Spring Boot and the actuator starter

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

you can check the endpoint /beans

查看更多
登录 后发表回答