Skip to content

Quarkus annotations

AnnotationPurposeExample
@InjectInject dependency@Inject UserService service;
@ApplicationScopedOne instance for application@ApplicationScoped class UserService {}
@SingletonSingleton bean@Singleton class ConfigService {}
@RequestScopedOne bean per request@RequestScoped class RequestContext {}
@SessionScopedOne bean per session@SessionScoped class ShoppingCart {}
@DependentDefault scope@Dependent class Helper {}
@NamedNamed bean@Named("paypal")
@ProducesProduce custom bean@Produces DataSource ds()
@DisposesCleanup produced beanvoid close(@Disposes Connection c)
@AlternativeAlternative implementation@Alternative class MockService {}
@PriorityActivate alternative@Priority(1)
@QualifierCustom bean qualifier@OnlinePayment
@PostConstructInitializationvoid init()
@PreDestroyCleanupvoid destroy()

AnnotationPurposeExample
@PathREST path@Path("/users")
@GETHTTP GET@GET
@POSTHTTP POST@POST
@PUTHTTP PUT@PUT
@DELETEHTTP DELETE@DELETE
@PATCHHTTP PATCH@PATCH
@ProducesResponse type@Produces(JSON)
@ConsumesRequest type@Consumes(JSON)
@PathParamURL variableget(@PathParam("id") Long id)
@QueryParamQuery parameter?page=1
@HeaderParamHeader value@HeaderParam("Authorization")
@CookieParamCookie@CookieParam("token")
@BeanParamAggregate paramsUserRequest request
@FormParamForm field@FormParam("name")

AnnotationPurposeExample
@ProviderRegister provider@Provider class Mapper
ExceptionMapper<T>Handle exceptionsimplements ExceptionMapper<Exception>
ContainerRequestFilterBefore requestimplements ContainerRequestFilter
ContainerResponseFilterBefore responseimplements ContainerResponseFilter
ReaderInterceptorRead request bodyimplements ReaderInterceptor
WriterInterceptorModify responseimplements WriterInterceptor

AnnotationPurposeExample
Event<T>Fire eventevent.fire(order)
@ObservesObserve synchronouslyonCreate(@Observes Order o)
@ObservesAsyncObserve asynchronouslyonCreate(@ObservesAsync Order o)

AnnotationPurposeExample
@StartupCreate bean at startup@Startup class CacheLoader {}
StartupEventApplication startedonStart(@Observes StartupEvent e)
ShutdownEventApplication stoppingonStop(@Observes ShutdownEvent e)

AnnotationPurposeExample
@ConfigPropertyInject property@ConfigProperty(name="app.name")
@ConfigMappingTyped configinterface AppConfig {}
@WithDefaultDefault value@WithDefault("8080")

AnnotationPurposeExample
@TransactionalTransaction boundary@Transactional save()
@TransactionScopedTransaction scope@TransactionScoped class Context {}

AnnotationPurposeExample
@EntityDatabase entity@Entity class User {}
@TableTable mapping@Table(name="users")
@IdPrimary key@Id Long id;
@GeneratedValueAuto-generated ID@GeneratedValue
@ColumnColumn mapping@Column(name="email")
@OneToManyOne-to-many relationList<Order> orders;
@ManyToOneMany-to-one relationUser owner;
@OneToOneOne-to-one relationProfile profile;
@ManyToManyMany-to-many relationSet<Role> roles;
@VersionOptimistic locking@Version Long version;
ClassPurposeExample
PanacheEntityActive Recordclass User extends PanacheEntity
PanacheRepositoryRepository patternimplements PanacheRepository<User>

AnnotationPurposeExample
@ValidValidate objectcreate(@Valid UserDto dto)
@NotNullCannot be null@NotNull String name;
@NotBlankCannot be blank@NotBlank String email;
@SizeSize limits@Size(min=3,max=20)
@EmailEmail format@Email
@PatternRegex validation@Pattern(...)
@MinMinimum@Min(18)
@MaxMaximum@Max(100)
@PositivePositive value@Positive BigDecimal price;

AnnotationPurposeExample
@RolesAllowedRestrict by role@RolesAllowed("admin")
@PermitAllAllow everyone@PermitAll
@DenyAllDeny everyone@DenyAll
@AuthenticatedLogged-in users only@Authenticated

AnnotationPurposeExample
@ScheduledRun periodically@Scheduled(every="10s")

AnnotationPurposeExample
@IncomingConsume messages@Incoming("orders")
@OutgoingProduce messages@Outgoing("processed")
@ChannelInject channel@Channel("orders")
@BroadcastBroadcast message@Broadcast
@MergeMerge streams@Merge

AnnotationPurposeExample
@CacheResultCache result@CacheResult(cacheName="users")
@CacheInvalidateRemove cache@CacheInvalidate(cacheName="users")
@CacheInvalidateAllClear cache@CacheInvalidateAll(cacheName="users")
@CacheKeyCache key@CacheKey String id

AnnotationPurposeExample
@RetryRetry failed calls@Retry(maxRetries=3)
@TimeoutTimeout@Timeout(500)
@CircuitBreakerStop repeated failures@CircuitBreaker
@FallbackAlternative method@Fallback(fallbackMethod="backup")
@BulkheadLimit concurrency@Bulkhead(5)
@AsynchronousAsync execution@Asynchronous

AnnotationPurposeExample
@CountedCount calls@Counted
@TimedMeasure duration@Timed
@GaugeCurrent value@Gauge

AnnotationPurposeExample
@OperationAPI documentation@Operation(summary="Get User")
@APIResponseResponse docs@APIResponse(responseCode="200")
@ParameterParameter docs@Parameter(name="id")
@SchemaModel docs@Schema(description="User")
@TagAPI grouping@Tag(name="Users")

AnnotationPurposeExample
@ReadinessReady probe@Readiness
@LivenessAlive probe@Liveness
@StartupStartup probe@Startup (on a HealthCheck bean)

AnnotationPurposeExample
@RouteHTTP route@Route(path="/hello")
@BodyRequest body@Body JsonObject body

AnnotationPurposeExample
@QuarkusTestIntegration test@QuarkusTest class UserTest
@InjectMockMock bean@InjectMock UserService
@TestHTTPEndpointTarget endpoint@TestHTTPEndpoint(UserResource.class)
@TestHTTPResourceInject endpoint URL@TestHTTPResource URL url

AnnotationPurposeExample
@BuildStepBuild-time step@BuildStep void feature()
@RecorderRuntime recorder@Recorder class MyRecorder
@RecordRecord runtime actions@Record(STATIC_INIT)

Most Frequently Used (90% of Real Projects)

Section titled “Most Frequently Used (90% of Real Projects)”
AreaCore Building Blocks
CDI@Inject, @ApplicationScoped, @Singleton, @Produces
REST@Path, @GET, @POST, @Consumes, @Produces
EventsEvent<T>, @Observes, @ObservesAsync
Configuration@ConfigProperty, @ConfigMapping
Persistence@Entity, @Transactional, PanacheEntity, PanacheRepository
Validation@Valid, @NotNull, @Size
Security@RolesAllowed, @Authenticated
Caching@CacheResult, @CacheInvalidate
Messaging@Incoming, @Outgoing
Scheduling@Scheduled
Fault Tolerance@Retry, @CircuitBreaker, @Fallback
Observability@Timed, @Counted
Testing@QuarkusTest, @InjectMock