Injected Bean Example - Quarkus Typing CST Test
Loading…
Injected Bean Example — Quarkus Code
Use CDI to inject a bean into a Quarkus REST API.
import javax.ws.rs.*
import javax.ws.rs.core.MediaType
import javax.enterprise.context.ApplicationScoped
import javax.inject.Inject
@ApplicationScoped
@Path("/bean")
public class BeanResource {
@Inject
CounterService service
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getCount() {
return "Count: " + service.getCount()
}
}
@ApplicationScoped
class CounterService {
private int count = 0
public int getCount() { return count }
public int increment() { return ++count }
}Quarkus Language Guide
Quarkus is a Kubernetes-native Java framework designed for building cloud-native, high-performance applications. It emphasizes fast startup times, low memory usage, and developer productivity.
Primary Use Cases
- ▸Microservices development
- ▸RESTful APIs with JAX-RS
- ▸Serverless functions and cloud-native apps
- ▸Reactive event-driven applications
- ▸Integration with Kubernetes and OpenShift
Notable Features
- ▸GraalVM native image support for ultra-fast startup
- ▸Live coding with hot reload
- ▸Reactive programming support
- ▸Unified configuration system
- ▸Extensive extension ecosystem
Origin & Creator
Quarkus was created by Red Hat in 2019 to modernize Java development for cloud-native environments.
Industrial Note
Quarkus is ideal for Java projects requiring high-performance, fast-startup, and cloud-native deployment with containerized environments.