PART-12 | QUARKUS lifecycle annotations

Опубликовано: 30 Июнь 2026
на канале: let's try & learn
800
6

PART-12 | QUARKUS lifecycle annotations #quarkus #quarkuslifecycle#java



We often need to execute custom actions when the application starts and clean up everything when the application stops.

Write a Quarkus application with a main method

Be notified when the application starts
Be notified when the application stops


Steps:-

mvn io.quarkus.platform:quarkus-maven-plugin:2.11.3.Final:create -DprojectGroupId=org.acme -DprojectArtifactId=lifecycleTest -DnoCode






void onStart(@Observes StartupEvent ev) {
System.out.println("custom initialization codes onstart....");
}

void onStop(@Observes ShutdownEvent ev) {
System.out.println("custom clean up codes onStop...");
}


@PostConstruct
void init() {
System.out.println(" custom initialization codes PostConstruct....");
}

@PreDestroy
void destroy() {
System.out.println("custom clean up codes PreDestroy......");
}