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.
Subscribe to my newsletter
Read articles from Bikash Mainali directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Bikash Mainali
Bikash Mainali
Experienced Java/JavaScript full-stack developer over 6 years of extensive expertise serving key role on elite technical teams developing enterprise software for healthcare, apple ad-platform, banking, and e-commerce. Adaptable problem-solver with high levels of skill in Groovy, Java, Spring, Spring Boot, Hibernate, JavaScript, TypeScript, Angular, Node, Express, React, MongoDB, IBM DB2, Oracle, PL/SQL, Docker, Kubernetes, CI/CD pipelines, AWS, Micro-service and Agile/Scrum. Strong technical skills paired with business-savvy UI design expertise. Personable team player with experience collaborating with diverse cross-functional teams.