You are developing a Spring Boot application where a bean is required to perform a task immediately after the ApplicationContext has been started. How would you implement this?
- Implement a custom event listener that listens for the ContextRefreshedEvent and executes the task.
- Use the @EventListener annotation on a method and specify the event type as ApplicationStartedEvent.
- Use the @OnStartup annotation on the bean's method.
- Use the @PostConstruct annotation on the bean's method that needs to run after startup.
To execute a task immediately after the ApplicationContext has been started in a Spring Boot application, you can implement a custom event listener that listens for the ContextRefreshedEvent. This event is raised when the ApplicationContext is fully initialized and ready to use. You can then execute your task in response to this event.
Loading...
Related Quiz
- In a Spring Boot project, which file is primarily used to declare project dependencies?
- In a typical Spring Boot application, which of the following is used to assert that the actual result meets the expected result?
- What is the primary purpose of using Mockito in unit testing?
- Which of the following annotations is used to map a web request to a specific handler method?
- When developing reactive applications in Spring Boot, which annotation is used to define a reactive controller?