What should be the output?
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
//@Order(2)
@Component
class Lie implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
System.out.println("Truth is behind the lies");
System.out.println("This is working perfectly");
throw new Exception("Does this work?");
}
}
//@Order(1)
@Component
class Truth implements CommandLineRunner {
@Override
public void run(String... args) {
System.out.println("Truth is in your eyes");
}
}
}
Output:
Truth is in your eyes
Truth is behind the lies
This is working perfectly
Exception in "Does this work?"
NOTE:
the order of execution of CommandLineRunner
components is not guaranteed. If you want to specify the order of execution, you can use the @Order
annotation along with the CommandLineRunner
components.