Spring/Spring
Spring) 등록된 Bean 확인하기
backend dev
2023. 1. 31. 22:22
@SpringBootApplication
public class AirbnbApplication implements CommandLineRunner {
@Autowired
private ApplicationContext ac;
public static void main(String[] args) {
SpringApplication.run(AirbnbApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
String[] beanDefinitionNames = ac.getBeanDefinitionNames();
Arrays.sort(beanDefinitionNames);
for (String beanDefinitionName : beanDefinitionNames) {
System.out.println("beanDefinitionName = " + beanDefinitionName);
}
}
}
CommandLineRunner라는 인터페이스를 구현해주면된다.
run이라는 메소드를 오버라이드 해주면된다.
ApplicationContext를 주입받는 부분도 필요하다.
ac.getBeanDefinitionNames()로 빈메타정보이름을 받아오고
정렬한후
출력해준다.
springboot가 기본으로 등록하는 빈들도 보이고,
내가 등록한 빈들도 확인된다.
How can I check if a bean has been loaded by springboot
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 spring...
stackoverflow.com