I am trying to figure how you are supposed to gracefully fail during application startup in quarkus.
- i tried adding this to the application startup code. This is right now not being called if i run one of the unit tests. It is only called if i start the application directly. I was hoping to return a non zero value as oppose to throwing an exception. This might be the recomended approach. I am not sure.
public class MyApp implements QuarkusApplication {
@Override
public int run(String... args) throws Exception {
System.out.println("Do startup logic here");
Quarkus.waitForExit();
return 0;
}
- i also tried raising an exception from the onStart lifecycle event. But it seems quarkus kept continuing its execution
void onStart(@Observes StartupEvent ev) {
LOGGER.info("The application is starting...");
}
void onStop(@Observes ShutdownEvent ev) {
LOGGER.info("The application is stopping...");
}
I am not sure if this is a feature request a bug or i am missing something and this is normal behaviour.
Edit1: Just to be clear:
@Startup
@ApplicationScoped
public class StarterBean {
private static final Logger LOGGER = Logger.getLogger("");
public StarterBean() {
throw new RuntimeException("failed misrably");
}
}
when i run with "./gradlew quarkusDev` i see the exception in the console but the application never exists. I was thinking it should. It does exit during unit tests and properly fails. I tried moving the exception in the onStart and that did not help as well. I also tried combinations of having each of Startup,ApplicationScoped or both
Edit2:
I tested it by building the uber jar and running that. Raising the exception does quit the application. Also as one can imagine the application also exits when running in the docker container. I am puzzled why the gradle task never exist. So to that end i think i will accept the answer . Thank you so much for your help !