1package com.example.springboot;
2
3import java.util.Arrays;
4
5import org.springframework.boot.CommandLineRunner;
6import org.springframework.boot.SpringApplication;
7import org.springframework.boot.autoconfigure.SpringBootApplication;
8import org.springframework.context.ApplicationContext;
9import org.springframework.context.annotation.Bean;
10
11@SpringBootApplication
12public class Application {
13
14 public static void main(String[] args) {
15 SpringApplication.run(Application.class, args);
16 }
17
18 @Bean
19 public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
20 return args -> {
21
22 System.out.println("Let's inspect the beans provided by Spring Boot:");
23
24 String[] beanNames = ctx.getBeanDefinitionNames();
25 Arrays.sort(beanNames);
26 for (String beanName : beanNames) {
27 System.out.println(beanName);
28 }
29
30 };
31 }
32
33}Copy