@@ -190,6 +190,7 @@ A bean represented by a class, producer method or field annotated with `@Startup
190
190
----
191
191
package org.acme.lifecycle;
192
192
193
+ import io.quarkus.runtime.Startup;
193
194
import jakarta.enterprise.context.ApplicationScoped;
194
195
195
196
@Startup // <1>
@@ -210,6 +211,57 @@ NOTE: `@Dependent` beans are destroyed immediately afterwards to follow the beha
210
211
211
212
TIP: If a class is annotated with `@Startup` but with no scope annotation then `@ApplicationScoped` is added automatically.
212
213
214
+ The `@Startup` annotation can be also declared on a non-static non-producer no-args method:
215
+
216
+ [source,java]
217
+ ----
218
+ package org.acme.lifecycle;
219
+
220
+ import io.quarkus.runtime.Startup;
221
+ import jakarta.enterprise.context.ApplicationScoped;
222
+
223
+ @ApplicationScoped
224
+ public class EagerAppBean {
225
+
226
+ @Startup
227
+ void init() { <1>
228
+ doSomeCoolInit();
229
+ }
230
+ }
231
+ ----
232
+ <1> The bean is created and the `init()` method is invoked upon the contextual instance when the application starts.
233
+
234
+ [[shutdown_annotation]]
235
+ === Using `@Shutdown` to execute a business method of a CDI bean during application shutdown
236
+
237
+ The `@io.quarkus.runtime.Shutdown` annotation is used to mark a business method of a CDI bean that should be executed during application shutdown.
238
+ The annotated method must be non-private and non-static and declare no arguments.
239
+ The behavior is similar to a declaration of a `ShutdownEvent` observer.
240
+ The following examples are functionally equivalent.
241
+
242
+ [source,java]
243
+ ----
244
+ import io.quarkus.runtime.Shutdown;
245
+ import io.quarkus.runtime.ShutdownEvent;
246
+ import jakarta.enterprise.context.ApplicationScoped;
247
+
248
+ @ApplicationScoped
249
+ class Bean1 {
250
+ void onShutdown(@Observes ShutdownEvent event) {
251
+ // place the logic here
252
+ }
253
+ }
254
+
255
+ @ApplicationScoped
256
+ class Bean2 {
257
+
258
+ @Shutdown
259
+ void shutdown() {
260
+ // place the logic here
261
+ }
262
+ }
263
+ ----
264
+
213
265
== Package and run the application
214
266
215
267
Run the application with:
0 commit comments