Spring Boot CommandLineRunner Interface Tutorial

preview_player
Показать описание
In this video, we will learn all about using the CommandLineRunner interface in spring boot application.

Spring boot’s CommandLineRunner interface is used to run a code block only once in the application’s lifetime – after an application is initialized.

In this video, we will discuss below 3 ways to use the CommandLineRunner interface:
1) Using CommandLineRunner as @Component
2) Implement CommandLineRunner in @SpringBootApplication
3) Using CommandLineRunner as Bean

#springboot #java #javaguides
Рекомендации по теме
Комментарии
Автор

Really good tutorial, thanks. But What I fail to grasp is why use this at all (or at least in main class) when you can do this in the main method? What's the advantage to write all this extra code when you can do the same thing in the main method?

AbdulMoizHaroon
Автор

Great coverage of the three ways to implement the command line running. I guess my only question might be, "why use one method over another"? Additionally, since the command line running can take arguments, I would have liked to see you show an example of those being used. I know most people at this level should know how to add arguments but it's an aspect of the command line and would have been nice to see at least one example of that. I've looked at many tutorials on the command line running and none of them demonstrate the use of arguments.

SimmeringPotpourri
Автор

Very much thankful for providing information about CommamdLineInterface. Can please explain @Order annotation.

S.D.Jani