How can I check if a bean has been loaded by springboot

Steven Smart :

I am trying to run some Grpc beans using Springboot and all I see confirmed is the springboot application loads. Where can I find confirmation that the beans loaded? Is there a way to start springboot so that it will show this?

Jaspreet Jolly :

The below code will log all the beans being loaded by spring application in its container:-

@SpringBootApplication
public class Application implements CommandLineRunner {

    @Autowired
    private ApplicationContext appContext;

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }

    @Override
    public void run(String... args) throws Exception {

        String[] beans = appContext.getBeanDefinitionNames();
        Arrays.sort(beans);
        for (String bean : beans) {
            System.out.println(bean);
        }

    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=329398&siteId=1