← All posts

Annotations | Quarkus bits

Annotations are metadata markers that provide information about the code but don't directly affect the code's operation. They are processed at compile-time or runtime by frameworks to generate code, inject dependencies, or modify behavior.

· 3 min read

How they work:

Compile-time processing (e.g., Lombok’s @Getter): The annotation processor generates additional code before compilation
Runtime processing (e.g., Spring’s @Inject): Frameworks scan annotations at startup and use reflection to inject beans, configure behavior, etc.

Why use annotations:

Reduce boilerplate: @Getter generates getters automatically instead of writing them manually
Configuration as code: @ConfigProperty binds config values without manual parsing
Dependency injection: @Inject eliminates manual object creation and wiring
Lifecycle management: @Startup runs code at specific application stages
Framework integration: Spring, Quarkus, etc. rely on annotations to manage beans and routes

Annotations:

`@ApplicationScoped` and `@Singleton`

In Quarkus (and CDI in general), both @ApplicationScoped and @Singleton give you “one instance for the whole application”, but they differ in how CDI manages that instance and in some practical behaviors.

What @ApplicationScoped does

Typical use: shared services, clients, and stateful components where you want CDI’s full lifecycle/proxy behavior.

What @Singleton does

Typical use: you really want a single instance with no proxy indirection, or the class cannot be proxied (e.g. final classes, some special cases).

Practical differences summarized

package com.seek.service;

import com.seek.components.job.service.JobRecommendationsService;
import jakarta.inject.Inject;

public class Test {

@Inject
JobRecommendationsService job;

public Test() {
}
}

/// quarkus
class QuarkustJobRecommendationsService {

JobRecommendationsService job;

public QuarkustJobRecommendationsService() {

}

public getJobRecommendations() {
get().getJobRecommendations();
}

private JobRecommendationsService get() {
if (job is null )
job = new JobRecommendationsService();

return job
}

}




./// DI Contaniner snippet code
Test test = new Test();

test.job = DIContainer.get(JobRecommendationsService);

← Back to all posts