Spring Boot 프로젝트 - 시작(2)

정지효·2023년 8월 9일

지난 포스트에 이어서 이번엔 실제 실행(run)되는 Application.java 파일에 기능을 더 추가해보자.

@SpringBootApplication
public class Application {

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

	@Bean
	public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
		return args -> {

			System.out.println("Let's inspect the beans provided by Spring Boot:");

			String[] beanNames = ctx.getBeanDefinitionNames();
			Arrays.sort(beanNames);
			for (String beanName : beanNames) {
				System.out.println(beanName);
			}

		};
	}

}

SpringApplication 객체는 스프링부트가 제공하는 객체이며, 스프링에서 웹 어플리케이션을 실행할 때 하는 것들 (web.xml구성파일 작성 등) 을 알아서 해주는 특징을 갖는다.

CommandLineRunner 메서드는 getBeanDefinitionNames를 실행하여 앱을 실행할 때 사용된 모든 Bean을 print 해준다. (중요한건 아님)

profile
백엔드 개발자

0개의 댓글